RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<jemc> are there known edge cases in the recursion detection of `inspect`?
<FromGitter> <girng> is there any security issues with allowing a user to enter any kind of text into a Array(String).new?
<jemc> I see that it works as desired for simple cases like this one:
<jemc> `crystal eval 'class X; property! field : X; end; a = X.new; b = X.new; a.field = b; b.field = a; p a'`
<jemc> `#<X:0x7fed12e84f20 @field=#<X:0x7fed12e84f00 @field=#<X:0x7fed12e84f20 ...>>>`
<jemc> But I have some cases in a more complicated program that seem to recurse indefinitely
<jemc> Is this a known issue? I didn't find a bug ticket about it, but maybe it's an unspoken knowledge?
<jemc> If it is not a known limitation, I can try to isolate a minimal repro and file a ticket
akaiiro has quit [Remote host closed the connection]
<FromGitter> <Sija> @jemc please do
<jemc> okay, thanks for confirming - will spend some time on that minimal repro
jemc has quit [Ping timeout: 244 seconds]
akaiiro has joined #crystal-lang
jemc has joined #crystal-lang
DTZUZO has joined #crystal-lang
akaiiro has quit [Ping timeout: 268 seconds]
DTZUZO has quit [Ping timeout: 250 seconds]
Renich_ has joined #crystal-lang
Renich has quit [Ping timeout: 250 seconds]
Renich_ is now known as Renich
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 246 seconds]
jemc has quit [Quit: WeeChat 2.2]
jemc has joined #crystal-lang
robacarp has quit [Ping timeout: 272 seconds]
Renich has quit [Remote host closed the connection]
Renich has joined #crystal-lang
robacarp has joined #crystal-lang
mrush has joined #crystal-lang
mrush has left #crystal-lang [#crystal-lang]
junland has quit [Quit: Disconnected.]
junland has joined #crystal-lang
<FromGitter> <girng> why don't i need to do array.delete! value????
<FromGitter> <girng> i was reading up about exclamation marks in ruby, (but i'm not sure if they mean the same crystal). but i read basically they are used if you want to modify that object itself, not the return value? and if you do array.delete value, it actually modifies the array itself. or am i missing something?
<FromGitter> <Blacksmoke16> sounds about right
<FromGitter> <girng> i mean tbh, i'm not complaining cause i mean array.delete value works just fine, and the array itself is modified. i was just thinking well, why don't i need to use array.delete! lol
<FromGitter> <codenoid> hi
<FromGitter> <codenoid> how to get current directory name in crystal
<FromGitter> <codenoid> `File.basename(__DIR__)`
<FromGitter> <anamba> `Dir.current`?
<FromGitter> <codenoid> thankyou @anamba
<FromGitter> <anamba> `File.basename(__DIR__)` is a little different, but either one could be what you need depending on the situation
<FromGitter> <codenoid> okay, but i already commit my code with File.basename(__DIR__)
<FromGitter> <codenoid> what, no, i mean current directory name
<FromGitter> <codenoid> not full path
<FromGitter> <codenoid> Dir.current is full path
<FromGitter> <anamba> ok, you can call basename on it then
<FromGitter> <anamba> are recursive types not recommended? thought i saw that somewhere. having some trouble with an alias of the form `alias Type = Int32 | String | Array(Type)` (simplified). i get a `can't cast Array(Int32) to Neo4j::Type`
<FromGitter> <anamba> the casting was to try to avoid this one: `instance variable '@value' of Hash::Entry(String | Symbol, Neo4j::Type) must be Neo4j::Type, not Array(Int32)`
<FromGitter> <anamba> i guess it's more of a general union type question. this kind of thing too, it seems like it should match, right? `no overload matches 'Array(Tuple(String, Hash(String | Symbol, Neo4j::Type)))#<<' with type Tuple(String, Hash(String, Neo4j::Type))` i always end up having to build a new hash to make this work.
<FromGitter> <codenoid> *DIR* is static value that collect value at compile time
jemc has quit [Ping timeout: 246 seconds]
DTZUZU has quit [Ping timeout: 268 seconds]
DTZUZU has joined #crystal-lang
ashirase has quit [Ping timeout: 268 seconds]
ashirase has joined #crystal-lang
<FromGitter> <proyb6> When can we participate in Crystal beta testing with HTTP/2? I find its a good time to allow us helping in the testing and file issue early
shmibs has quit [Quit: leaving =o]
<FromGitter> <proyb6> @asterite Awesome! 'a'.ord produce the exact codepoint
woodruffw has quit [Ping timeout: 244 seconds]
shmibs has joined #crystal-lang
woodruffw has joined #crystal-lang
<FromGitter> <vladfaust> @RX14 having plans on removing annotations? I mean, we were discussing their superiority against dynamic constants. If annotations are removed, there is no way to store data in compilation time πŸ˜•
<FromGitter> <vladfaust> Ary calmed me down
<FromGitter> <j8r> plan to remove inheritance, namedtuple, symbol, `[] of`/`{} of` syntax, `JSON.mapping`, `YAML.mapping`? :trollface:
<FromGitter> <vladfaust> Namedtuples aren't that bad
<FromGitter> <vladfaust> They-re good for inline code
<FromGitter> <vladfaust> Others are confusing, indeed
<RX14> who said removing annotations?
<FromGitter> <j8r> @vladfaust note there is still HashLiteral for macros
<FromGitter> <vladfaust> I don't get it
<FromGitter> <vladfaust> https://github.com/golang/oauth2 that looks so good
<FromGitter> <vladfaust> Yeah, I wonder if Crystal stdlib is going to be splitted
jemc has joined #crystal-lang
<FromGitter> <alehander42> what are annotations?
<FromGitter> <alehander42> something like tags for each method?
<FromGitter> <vladfaust> Yep, they're ugly but powerful
<FromGitter> <straight-shoota> @j8r Inheritance is useful for modelling similar concepts which only differ in specific behaviour but form a logical family of types which lots of shared behaviour. You could use composition for that. And you would have to in a non-OOP language. But OOP offers a better mechanic for this, which reduces a lot of friction. ⏎ A good example is the hierarchy of error classes. `Exception` is the base type
<FromGitter> ... and defines general behaviour of an exception. Some libraries define subtypes that inherit from `Exception` and implement some specific additions to the general interface (such as storing additional data about the error). ⏎ ⏎ Obviously, inheritance is not always a good choice. And in fact, sometimes developers have overused ... [https://gitter.im/crystal-lang/crystal?at=5c09349a28907a3c7bd98183]
<FromGitter> <vladfaust> Good read, @straight-shoota, thanks
<FromGitter> <kinxer> @vladfaust Annotations == Type Annotations?
<RX14> no
<RX14> @[Foo] annotations
<FromGitter> <j8r> @straight-shoota Back to crystal, this force to use Classes where Structs are would fit perfectly (or I'm dumb, can't use inheritance in Structs). This yield to less performance, more memory consumption, more unpredictability
<FromGitter> <straight-shoota> structs can use inheritance
<FromGitter> <straight-shoota> you can only inherit from abstract structs, though
<FromGitter> <straight-shoota> And even if inheritance was only possible with classes, noone would force you to use it if you could achieve a better result with compositing structs
<FromGitter> <j8r> yeah right, I was confusing with other langs
<FromGitter> <j8r> where structs are more rigid
<FromGitter> <j8r> Crystal struct are a bit special comparing to C, Go and Rust. They feels more like classes
<jokke> do you have workflows to create releases in CIs for shards?
<FromGitter> <j8r> who?
<jokke> why isn't there a possibility to pass structs (or any value) by reference?
<jokke> i like this about rust
<FromGitter> <alehander42> crystal structs sound like c# structs to me
<jokke> lot less for the the gc to do
<FromGitter> <alehander42> symbols vs enums is interesting
<jokke> i think of symbols like a huge global enum :D
<FromGitter> <j8r> jokke: good question. You can still pass pointers by reference, like `pointerof(MyStruct)`
<jokke> yeah but there's no safety like in rust
<jokke> rust tells you the reference will be cleaned up if you try passing it to something which will continue using it after it leaves scope
<jokke> don't get me wrong, i'm not a rust fanboy. i think it has great features like the above, but it's super verbose compared to crystal and usually just gets in my way.
hexreel has joined #crystal-lang
Renich_ has joined #crystal-lang
Renich has quit [Ping timeout: 244 seconds]
Renich_ is now known as Renich
<FromGitter> <proyb6> It's the first time I heard about jq
<robacarp> jq is great. I use it all the time
<RX14> same
<FromGitter> <j8r> @proyb6 for your comment, there is still room for improvement for JSON::PullParser
<FromGitter> <j8r> I'm estimating to 10~25%
<FromGitter> <proyb6> Great @j8r I think a benchmark on deep comparison and large amount of JSON data could be useful indicator for your shards as well
<FromGitter> <j8r> Sadly, that's not currently my priority but I'll send a PR in the future 😏
<FromGitter> <j8r> *to improve the stdlib's `JSON`
Renich_ has joined #crystal-lang
Renich has quit [Ping timeout: 250 seconds]
Renich_ is now known as Renich
jemc has quit [Ping timeout: 268 seconds]
akaiiro has joined #crystal-lang
<FromGitter> <proyb6> πŸ‘
jemc has joined #crystal-lang
<FromGitter> <j8r> but this doesn't stop to make benchmarks, I've already done some for small data
<RX14> JSON right now has the right structure, the rest is microoptimizations
<RX14> and thats a good place to be in
<RX14> s/structure/design
<FromGitter> <j8r> Not the more optimized
<FromGitter> <j8r> I've experienced a design with no Token class, directly returning the value
<FromGitter> <j8r> This yield to less allocations
<FromGitter> <j8r> and to replace the `on_key`, we can use `case/when`
<FromGitter> <j8r> the Builder is even more performant: it creates sub builder instead of one Builder keeping track of the structure
<FromGitter> <mhart> Hi all! A question about cross-compiling: if I do `crystal build --cross-compile` on a machine that has OpenSSL >= 1.1.0 (or >= 1.0.2), then I can't do the linking step on a machine that does not meet these OpenSSL requirements. So instead of the target being `x86_64-unknown-linux-gnu` it's technically really more accurately `x86_64-unknown-linux-gnu w/ openssl >= 1.1.0`. Digging around I'm guessing it's these
<FromGitter> ... sorts of macro checks that are responsible: https://github.com/crystal-lang/crystal/blob/0.27.0/src/openssl/lib_ssl.cr#L4-L17
<FromGitter> <mhart> My question is – what's the least hackiest way to specify the openssl version you want to target when doing a `crystal build --cross-compile`?
<FromGitter> <mhart> Is there a way to specifically set `OPENSSL_VERSION`? My guess is no. So then is the next least-hackiest way to somehow fool `pkg-config` into outputting what I want when this command is run? https://github.com/crystal-lang/crystal/blob/0.27.0/src/openssl/lib_ssl.cr#L8
<RX14> @mhart the best was is to edit the openssl.cr file and fix it manually, and hope you dont have to cross-compile often :P
<RX14> @j8r i meant the JSON api design, `on_key` is inlined remember so compiles to the same as `case`
<FromGitter> <mhart> @FromIRC yeah, I want to avoid that – it would be fine if it were just for me, but I'm outlining steps to do this for others
<FromGitter> <mhart> More specifically, I'm outlining steps for how ppl can compile for the AWS Lambda env
<FromGitter> <mhart> Which *doesn't* have OpenSSL 1.0.2
<FromGitter> <mhart> So I don't want to tell everyone to compile their own crystal
<FromGitter> <mhart> On my Mac I've had success with `PKG_CONFIG_PATH='' crystal build ...`
<FromGitter> <mhart> Because then `pkg-config` just fails to find OpenSSL – but that feels very brittle – I'd prefer something a little more robust
<FromGitter> <mhart> One option would be to have a sanctioned env var (eg, `OPENSSL_VERSION`) that is checked here, before invoking pkg-config: https://github.com/crystal-lang/crystal/blob/0.27.0/src/openssl/lib_ssl.cr#L8
<FromGitter> <mhart> Is that something that has precedence elsewhere in the crystal codebase? The ability to override certain preprocessor/macro args at build time?
<FromGitter> <j8r> RX14 true. the raw handling would change a bit however, not a big deal
<FromGitter> <j8r> yeah the API won't change at 90%
<RX14> @mhart perhaps copy old openssl's pkg-config file
<RX14> and put it in a dir and point PKG_CONFIG_PATH at that
<FromGitter> <j8r> since you're here RX14, I've pushed commits to https://github.com/crystal-lang/distribution-scripts/pull/23
<RX14> @j8r there's mixed tabs and spaces :/
<FromGitter> <j8r> true :/
<FromGitter> <j8r> 1 min I correct this
<FromGitter> <kinxer> Can a heredoc be used as a constant?
<FromGitter> <mhart> RX14 yeah, that's a good idea – haven't looked into how tricky that is – will try
<RX14> shouldnt be too hard
<FromGitter> <j8r> should I use tabs or spaces?
<RX14> spaces
<RX14> probably
<RX14> the tabs is just for rules i think
<Yxhuvud> Use whatever is used in the file already
<Yxhuvud> but it seems to be an ugly mix of them :X
<FromGitter> <j8r> ok, pushed a commit with spaces
<RX14> Yxhuvud, makefiles need tabs for indenting rules
<RX14> but the rest can be spaces
<FromGitter> <j8r> Best idea everβ„’
<FromGitter> <j8r> use different invisible characters for semantic
<RX14> yep
rohitpaulk has joined #crystal-lang
<FromGitter> <straight-shoota> But that's an trap literally everyone writing Makefiles has fallen
<FromGitter> <straight-shoota> I'd excuse it as an initiation ritual :D
<FromGitter> <j8r> I don't know why we are still using make
<FromGitter> <j8r> nowadays there are plenty of other alternatives
<FromGitter> <blakexcosta> I'm relatively new to this language, but I'm interested in helping. Does anyone know where would be a good place start? Or anyone that would be willing to work/learn together?
gangstacat has quit [Quit: Ĝis!]
<FromGitter> <straight-shoota> @j8r Because it's well known and ubiquitous
<FromGitter> <straight-shoota> @blakexcosta Great. We're happy for everyone joining =)
<FromGitter> <ilanusse> Welcome Blake! :)
<FromGitter> <ilanusse> If you come from Ruby, Crystal for Rubyists is pretty good: http://www.crystalforrubyists.com/
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <ilanusse> https://crystal-lang.org/docs/overview/ The docs are awesome, too
<FromGitter> <ilanusse> If you'd like to look at a small project to see what actual code looks like, you can look at a shard I made: https://github.com/ilanusse/praetorian
<FromGitter> <ilanusse> It's not the best code in the work but it gives you an idea of what Crystal can look like
<FromGitter> <straight-shoota> If you want to contribute, it's a good place to start with the standard library. Generally, you might take look at newcomer issues: https://github.com/crystal-lang/crystal/labels/community%3Anewcomer ⏎ However, the only ones currently tagged and still open are about OpenSSL. Not sure if that matches your interest.
<FromGitter> <j8r> @straight-shoota not sure about well-kown. Known yes, but very few people know how to properly do a Makefile right
<FromGitter> <ilanusse> @blakexcosta My current project is making a full authentication solution for Amber and Lucky, which are the biggest frameworks on Crystal rn, if it interests you, let me know
<FromGitter> <blakexcosta> @straight-shoota @ilanusse Thank you guys! that's exceptionally helpful. ⏎ ⏎ @ilanusse code examples are always exceptionally helpful. After I finish plowing through the docs, I'll take a look. ⏎ ⏎ @straight-shoota I'm happy to tackle whatever is available in the open lib :) [https://gitter.im/crystal-lang/crystal?at=5c09666480986419d54d140b]
<FromGitter> <blakexcosta> @ilanusse I'm definitely interested.
<FromGitter> <straight-shoota> @j8r It certainly has a larger userbase than any more modern alternative tool
<FromGitter> <vladfaust> Okay now we need DHH in this chat and then Matz
non-aristotelian has joined #crystal-lang
gangstacat has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 246 seconds]
<coderobe> Anyone know any shard that implements any sort of font parsing
<FromGitter> <greenbigfrog> as in image to text?
<FromGitter> <j8r> @straight-shoota better to use Ruby instead of Crystal so, because it has a larger userbase 😁
<FromGitter> <j8r> Ruby has Rake
<FromGitter> <j8r> We could have Crake :)
<FromGitter> <Blacksmoke16> Cake
<FromGitter> <Blacksmoke16> *the cake is a lie*
<FromGitter> <j8r> Haha
<FromGitter> <j8r> Today we already have https://github.com/tbrand/neph
<FromGitter> <j8r> @Blacksmoke16 The Crystal cake is a lie. I hope not
<FromGitter> <kinxer> So, if a cake is primarily layered, would a crystal cake be mica (https://en.wikipedia.org/wiki/Mica)?
<FromGitter> <mhart> Question for those in the know – I'm going to statically link in libevent to my crystal binary – would it be better to use libevent 2.1.8 or 2.0.22? It seems to work with 2.1.8, and as that's the latest stable I'm tempted to prefer it, but there might be some feature introduced in 2.1 that breaks some aspect of crystal I haven't run into yet. Anyone have any opinions on this?
Renich_ has joined #crystal-lang
Renich has quit [Ping timeout: 246 seconds]
Renich_ has quit [Read error: Connection reset by peer]
<FromGitter> <j8r> @Blacksmoke16 The Crystal cake is a lie. I hope not
Renich has joined #crystal-lang
<FromGitter> <j8r> @kinxer well found name!
<FromGitter> <vladfaust> Mica looks a lot like halva http://clc.am/7jdNpA
<FromGitter> <kinxer> @j8r Thanks, but I think we're actually trying to find a play on "Rake", right?
<FromGitter> <kinxer> @vladfaust Where I grew up it was more often found as part of small, thin stones, so I'm gonna have to disagree. :P
<coderobe> greenbigfrog: more like the other way around, really
<coderobe> any-font-data-to-arbitrarily-sized-bitmap or something magical like that :P
<FromGitter> <girng> @blakexcosta welcome!! check docs (https://crystal-lang.org/api) and fiddle around in the crystal playground (https://play.crystal-lang.org/). that's what i did when i first started. and ofc, you can ask questions on gitter, reddit, stack overflow
Renich has quit [Remote host closed the connection]
daemonwrangler has quit [Ping timeout: 246 seconds]
<FromGitter> <vladfaust> Why does JSON::Serializable has these LoC -- https://github.com/crystal-lang/crystal/blob/c9d1eef8fde5c7a03a029d64c8483ed7b4f2fe86/src/json/serialization.cr#L119-L122 ⏎ ⏎ Why not making `def initialize(*, __pull_for_json_serializable pull : ::JSON::PullParser)` protected and call it from `self.new`?
<FromGitter> <vladfaust> I get it, to avoid recursion
<FromGitter> <vladfaust> I nailed it marking the main initializer private and adding a `*, *serialization*flag`to it: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c099a1ce4787d16e3578802]
jemc has quit [Ping timeout: 272 seconds]
<FromGitter> <vladfaust> But I guess I've lots of duplication...
<FromGitter> <vladfaust> Sorry for shitposting. This is actually good, that manual allocation, allows to separate `self.new` from `initialize`
<FromGitter> <straight-shoota> @vladfaust No, it's not about recursion
<FromGitter> <vladfaust> Care to give an explanation, @straight-shoota ?
<FromGitter> <elorest> Is there a better way to work with bits in crystal? https://carc.in/#/r/5pmg ⏎ ⏎ In this example I'm trying to pull 3 values out of 40 bits.
<FromGitter> <elorest> <oprypin> this seems like the sort of question you would have the answer too.
<FromGitter> <straight-shoota> @vladfaust visibility of `new` with pull parser argument
<FromGitter> <vladfaust> Ah, okay
<FromGitter> <straight-shoota> it should be defined directly on the included type
daemonwrangler has joined #crystal-lang
<FromGitter> <vladfaust> I partially understand it. But the "big" initializer (https://github.com/crystal-lang/crystal/blob/c9d1eef8fde5c7a03a029d64c8483ed7b4f2fe86/src/json/serialization.cr#L135) is defined on inclusion as well, isn't it?
<FromGitter> <vladfaust> As it's being a part of the module
<FromGitter> <vladfaust> If so, why need to wrap it with `macro included; self.new ...` then?
<FromGitter> <vladfaust> Why not just replacing `def initialize(*, __pull_for_json_serializable pull : ::JSON::PullParser)` with `def initialize(pull : ::JSON::PullParser)`? ⏎ ⏎ I experimented and found out that in this case sometimes a nested object doesn't have `def initialize(pull : ::JSON::PullParser)` yet
<oprypin> elorest, nah this seems fine. just don't write out that `4294967295` manually. if you wanna be really cutesy, you could write a macro to generate these methods based on provided sizes and names
<FromGitter> <blakexcosta> @girng thank you! I appreciate the advice
<oprypin> elorest, lol seems like macros can work only with int32, so womp womp
<FromGitter> <elorest> <oprypin> ⏎ ⏎ > @elorest, nah this seems fine. just don't write out that 4294967295 manually. if you wanna be really cutesy, you could write a macro to generate these methods based on provided sizes and names ⏎ ⏎ I can think of a few ways to do this with pretty much the same method. I was just hoping there was a different way to handle bits like bitfields in C or something. In this example I could fit
<FromGitter> ... all of my data into an Int64. Not sure what I would do with larger chunks. [https://gitter.im/crystal-lang/crystal?at=5c09a91cf992693c7a3318e2]
<oprypin> elorest, oh, you have larger chunks? shoulda started with that
<FromGitter> <elorest> Sorry.
<FromGitter> <elorest> > just don't write out that 4294967295 manually ⏎ ⏎ What would be the alternative? `2**32 - 1`
<FromGitter> <elorest> That's probably cleaner.
<oprypin> I was hoping for `{{2**32 - 1}}` but that's `-1` :D
<FromGitter> <elorest> Could probably at least be put into a const.
<FromGitter> <elorest> Any idea how I could pass in chunks larger that Int64? Possibly Slice somehow?
<oprypin> elorest, LOL i just had some fun with the code https://carc.in/#/r/5pnc
<FromGitter> <elorest> :)
<oprypin> https://crystal-lang.org/api/0.27.0/BitArray.html is kinda promising but it has no way to obtain a range as a number
<FromGitter> <elorest> I was looking at it but also found this odd. ` ⏎ ⏎ > Bits externally represented as Bools are stored internally as UInt32s. The total number of bits stored is set at creation and is immutable
<FromGitter> <elorest> Are there integer types in crystal smaller than uint8?
<oprypin> no
<FromGitter> <elorest> Afraid of that. I could have used a slice to break them up in that case though.
jemc has joined #crystal-lang
<FromGitter> <elorest> Still could for the most part though.
<oprypin> aha! https://crystal-lang.org/api/0.27.0/BitArray.html#to_slice%3ABytes-instance-method
<oprypin> meh, still not very nice
<FromGitter> <elorest> https://carc.in/#/r/5pnf
<FromGitter> <elorest> Last 2 lines. Not great but for the few bytes store multiple values in subbytes I could handle manually.
<oprypin> elorest, this is sad. https://carc.in/#/r/5pnr
<oprypin> very universal tho!
<oprypin> uses like 3 reallocation each time
<FromGitter> <elorest> Thanks. That's handy to know. I'm leaning toward just writing it in C and populating a struct that I use c bindings to move over.
<FromGitter> <elorest> It feels less wrong using pointers in C lol
<oprypin> ah no, that's not it
<FromGitter> <elorest> This would be handy if it was ever built. From reading through it I'm not 100% sure if it was sort of added or not. https://github.com/crystal-lang/crystal/issues/3898
<RX14> it wasnt added
<oprypin> oh no, it's definitely not worth it
<FromGitter> <elorest> Does it make sense to you guys just to use bitfields in C and then C bindings to use it in crystal?
<oprypin> elorest, this is actually legit https://carc.in/#/r/5po7
<oprypin> why am i like this, though
<oprypin> bugfix https://carc.in/#/r/5po9