ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<watzon> Does anyone know of something like IO::ByteFormat for Ruby? All I've managed to find is bitpack, but it hasn't been touched in 11 years.
<watzon> All of the gems that deal with binary seem to be more declarative
sz0 has quit [Quit: Connection closed for inactivity]
hendursaga has joined #crystal-lang
<hendursaga> Hello all! I finally got around to checking Crystal out, and so far it looks good! I loved Ruby's syntax and idioms, but didn't like its speed, or lack thereof.
<FromGitter> <Blacksmoke16> good to hear!
<hendursaga> The biggest thing that worries me is the lack of parallelism - but I suppose that might be added on sometime down the road?
<hendursaga> Hmmm. Do you still need to opt-in?
<FromGitter> <Blacksmoke16> yes
<hendursaga> State of REPL? I suppose it'd be hard like in Rust..
<FromGitter> <Blacksmoke16> there are some projects like https://github.com/crystal-community/icr. But IMO it's just as easy to have a `test.cr` file that you can mess with
<FromGitter> <Blacksmoke16> or even setup `nodemon` to watch it and recompile automatically
aquijoule__ has joined #crystal-lang
aquijoule_ has quit [Ping timeout: 265 seconds]
chachasmooth has quit [Ping timeout: 264 seconds]
chachasmooth has joined #crystal-lang
hendursaga has quit [Remote host closed the connection]
hendursaga has joined #crystal-lang
sz0 has joined #crystal-lang
_whitelogger has joined #crystal-lang
_ht has joined #crystal-lang
postmodern has joined #crystal-lang
teardown has quit [Remote host closed the connection]
teardown has joined #crystal-lang
aquijoule__ has quit [Ping timeout: 240 seconds]
hendursa1 has joined #crystal-lang
hendursaga has quit [Ping timeout: 268 seconds]
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
<FromGitter> <HertzDevil> so i got general pattern matching almost working with macros (good enough to define the matching semantics)
<FromGitter> <HertzDevil> time to write a full spec
<FromGitter> <alexherbo2> how create a named tuple from an array of values?
postmodern has quit [Quit: Leaving]
<FromGitter> <asterite> @HertzDevil Wow, nice! What does "general pattern matching" mean in Crystal?
<FromGitter> <HertzDevil> i want something similar to ruby 3's (single-statement) `=>` or `in` operator and i'm sure some others want it too
<FromGitter> <HertzDevil> if we have it, we could also extend case expressions in terms of such an operator
<FromGitter> <HertzDevil> (ruby had it backwards and defined the single-statement `in` in terms of a case expression)
<FromGitter> <HertzDevil> will be gathering some initial thoughts on the forum before making an issue
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 272 seconds]
<FromGitter> <mohsinhijazee> Hello community. Is it possible to dynamically load a file and evaluate it? Like crystal eval but from within the program (somewhere there there's no crystal installation)?
deavmi has joined #crystal-lang
<straight-shoota> You can compile the compiler into your program use it to build the eval file and execute that program
<straight-shoota> at runtime
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
<FromGitter> <asterite> @HertzDevil is the pattern matching you are doing type safe?
<FromGitter> <HertzDevil> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=6033bd8b8031c8234bf97df4]
<FromGitter> <HertzDevil> it is
<FromGitter> <HertzDevil> the whole thing expands to a nested if expression like
<FromGitter> <HertzDevil> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=6033befd47585464db951fd3]
<FromGitter> <asterite> Nice!
<FromGitter> <asterite> So it's runtime pattern matching... I guess it's what we have right now too
<FromGitter> <asterite> Pattern matching is an overloaded term :/
HumanG33k has quit [Quit: Leaving]
HumanG33k has joined #crystal-lang
<FromGitter> <jrei:matrix.org> @alexherbo2: you can use the regular namedtuple literal
<FromGitter> <jrei:matrix.org> Like `{a: ary[0], b: ary[1]}`
<FromGitter> <alexherbo2> :(
<FromGitter> <jrei:matrix.org> The keys must be known at compile-time
<FromGitter> <alexherbo2> I would hope we could pull the named tuple from an array
<FromGitter> <Blacksmoke16> would be possible if you first make the array into a hash, maybe with `.zip`
<FromGitter> <Blacksmoke16> then can use https://crystal-lang.org/api/master/NamedTuple.html#from(hash:Hash):self-class-method
<FromGitter> <alexherbo2> also, it's not ideal when using an array of named tuple, we cannot `.from` on the container
<FromGitter> <Blacksmoke16> but the better solution is to not use named tuples like this
<FromGitter> <Blacksmoke16> just use an array of structs or something
<FromGitter> <alexherbo2> `data = [] of { session: String, client: String, buffer_name: String, working_directory: String }`
<FromGitter> <Blacksmoke16> gross
<FromGitter> <Blacksmoke16> `data = [] of SomeType`
<FromGitter> <Blacksmoke16> `record SomeType, session: String, client: String, buffer_name: String, working_directory: String`
<FromGitter> <jrei:matrix.org> Yeah
<FromGitter> <jrei:matrix.org> Use structs, then you can add macro helpers inside
<FromGitter> <alexherbo2> you would declare a custom type even if it is just used for in the cli for a display?
<FromGitter> <Blacksmoke16> probably
<FromGitter> <jrei:matrix.org> Can you provide an example in carc.in?
<FromGitter> <jrei:matrix.org> We will see whag fits the best ;)
<FromGitter> <Blacksmoke16> yea id just use a record
<FromGitter> <Blacksmoke16> can even do like `private record ...` if you dont want to expose it
<FromGitter> <alexherbo2> I noticed a bug in the option parser, for named command
<FromGitter> <alexherbo2> I have a `kcr shell` command, handling the `shell` command. when I run `kcr fzf shell`, it is recognized as `kcr shell`
<FromGitter> <alexherbo2> it should not recognize `shell`, because there is `fzf` before
teardown has quit [Ping timeout: 268 seconds]
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU__ has joined #crystal-lang
DTZUZU_ has quit [Ping timeout: 256 seconds]
<FromGitter> <jrei:matrix.org> perhaps you better off using a library
<FromGitter> <jrei:matrix.org> OptionParser is nice for littles CLIs, less for bigger ones
<FromGitter> <erdnaxeli:cervoi.se> yes
<FromGitter> <jrei:matrix.org> if you like NamedTuples and descriptive over imperative, you may like https://github.com/j8r/clicr
DTZUZU__ is now known as DTZUZU
<FromGitter> <kingsleyh> does anyone know if adding uniq to an array is likely to cause performance issues? I added one to an array and it gets hit 1000's of times per second but now the CPU is double what it was and that seems to be one of the only things I changed that sticks out to me
<FromGitter> <Blacksmoke16> i mean it would need to create a new array and iterate it fully so prob would have an impact, also depending on the size of the array
<FromGitter> <jrei:matrix.org> uniq or uniq!?
<FromGitter> <jrei:matrix.org> also consider using a Set
<FromGitter> <kingsleyh> uniq
<FromGitter> <kingsleyh> I think a Set is a fantastic idea!!!
<FromGitter> <oprypin:matrix.org> @kingsleyh: j8r (https://matrix.to/#/@jrei:matrix.org) uniq uses a set already. https://github.com/crystal-lang/crystal/blob/248dd97/src/array.cr#L1854
<FromGitter> <kingsleyh> could my CPU go up by adding uniq to an array?
<FromGitter> <kingsleyh> or is that unlikely and it must be something else?
<FromGitter> <jrei:matrix.org> That's good then using Set
<FromGitter> <oprypin:matrix.org> sure
<FromGitter> <oprypin:matrix.org> it could go up
<FromGitter> <kingsleyh> I'm re-implementing it and will benchmark it
<FromGitter> <jrei:matrix.org> a Set is created anyway, better using one first
<FromGitter> <jrei:matrix.org> it is a good change, even if this is not the cause,
chachasmooth_ has joined #crystal-lang
chachasmooth has quit [Ping timeout: 260 seconds]
<FromGitter> <asterite> @kingsleyh how big is the array you are calling `uniq` on?
<FromGitter> <asterite> I ask because if it's a small array (less than 17 elements) it deletes things in place, otherwise it needs to create a Hash with all the values and then get the uniq keys, which can be pretty expensive
maxpowa has quit [Ping timeout: 260 seconds]
maxpowa has joined #crystal-lang
<FromGitter> <jrei:matrix.org> @asterite: I was not able to reproduce https://github.com/crystal-lang/crystal/issues/10359#issuecomment-783321224
<FromGitter> <jrei:matrix.org> I did the the checkout, make clean, and `echo > foo.cr`
<FromGitter> <asterite> what LLVM version?
<FromGitter> <jrei:matrix.org> LLVM 11.0.1
<FromGitter> <jrei:matrix.org> on Linux
<FromGitter> <asterite> well, i'm on mac, maybe that's why
<FromGitter> <jrei:matrix.org> wait, I may need to compile the compiler (make clean), then compile the compiler with it
<FromGitter> <jrei:matrix.org> I would like to bisect, but it is going to take a lot of time :/
<FromGitter> <oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org): so what did u reproduce here lol https://github.com/crystal-lang/crystal/issues/10359#issuecomment-780686951
teardown has joined #crystal-lang
<FromGitter> <jrei:matrix.org> oprypin (https://matrix.to/#/@oprypin:matrix.org): I reproduced with the issue's code
<FromGitter> <jrei:matrix.org> not an empty program. I think going to compile the compiler will do it, I'm doing it
<FromGitter> <jrei:matrix.org> Indeed, it was this - just reproduced
<FromGitter> <oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org): so let's make an automatic repro and run it
<FromGitter> <oprypin:matrix.org> please put what you have
<FromGitter> <jrei:matrix.org> of course I'm writing a comment right now
<FromGitter> <jrei:matrix.org> that's why I'm doing it :)
<FromGitter> <jrei:matrix.org> how can I force the `make` command instead of having `make: Nothing to be done for 'crystal'.`
<FromGitter> <jrei:matrix.org> for now I'm just touching a random file in `src/`
<FromGitter> <jrei:matrix.org> got it `-B`
richbridger has joined #crystal-lang
<FromGitter> <oprypin:matrix.org> ok cya later
<FromGitter> <Blacksmoke16> cant you just run `make clean` first?
<FromGitter> <oprypin:matrix.org> aha nice comment
<FromGitter> <jrei:matrix.org> time for a one day bisect :/
<FromGitter> <oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org): what exactly happens when u run `bin/crystal run --release a.cr`
teardown has quit [Ping timeout: 268 seconds]
<FromGitter> <jrei:matrix.org> a sigfault
<FromGitter> <oprypin:matrix.org> @Blacksmoke16: apparently not, because that deletes the compiler we're trying to use :D
<FromGitter> <Blacksmoke16> oof, fair point ha
<FromGitter> <jrei:matrix.org> I'll start with Crystal 0.35.1
<FromGitter> <jrei:matrix.org> hopefully `https://dist.crystal-lang.org/apt` is still there for quick & easy 0.35.1 install :D
<FromGitter> <Blacksmoke16> could prob just grab it from the GH release
<FromGitter> <jrei:matrix.org> sure, but slower
<FromGitter> <jrei:matrix.org> I'll use docker if it was not available
<FromGitter> <jrei:matrix.org> but I want max perf because it is going to be very very long
teardown has joined #crystal-lang
<FromGitter> <jrei:matrix.org> oprypin (https://matrix.to/#/@oprypin:matrix.org): you started a bisect too, we'll see which one is the fastest haha
<FromGitter> <jrei:matrix.org> You'll probably be faster than me, I have a Ryzen 5 1600 AF. Even putting the governor to performance does not change much
<FromGitter> <jrei:matrix.org> it is still good to do it both, I do with LLVM 11 and you 10
<FromGitter> <oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org): wait i thought crystal 0.35.1 doesnt support llvm 11
<FromGitter> <oprypin:matrix.org> thats why i got llvm 10 seeing the error
<FromGitter> <jrei:matrix.org> ...oops yes
<FromGitter> <jrei:matrix.org> true, true
<FromGitter> <jrei:matrix.org> doing it back with `export LLVM_CONFIG=/usr/bin/llvm-config-10`
<FromGitter> <kingsleyh> if there are 2 shards with the same name - and the same require "shard" - is it possible to use them both at the same time?
<FromGitter> <kingsleyh> can you alias one of the requires ?
<FromGitter> <Blacksmoke16> possibly, assuming none of the methods/type names conflict
<FromGitter> <Blacksmoke16> no
<FromGitter> <kingsleyh> well the require is the same so that is a problem lol
<FromGitter> <jrei:matrix.org> no point of having the same name
<FromGitter> <jrei:matrix.org> define different ones in shard.yml
<FromGitter> <kingsleyh> yeah just two of the shards have the same name
<FromGitter> <kingsleyh> how do you require them tho?
<FromGitter> <Blacksmoke16> id vote try and get one of them to change their name
<FromGitter> <kingsleyh> well this one was added 3 months ago: https://github.com/lbarasti/rate_limiter
<FromGitter> <kingsleyh> adnd this one was 3 years ago: https://github.com/z64/rate_limiter
<FromGitter> <Blacksmoke16> cant just use one?
<FromGitter> <oprypin:matrix.org> probably dependency tree
<FromGitter> <kingsleyh> I want to try the new one and I already have the old one - and don't want to rip out all the old one at once
<FromGitter> <kingsleyh> there is only 1 file - I might just copy paste it for now
<FromGitter> <kingsleyh> but it would be cool to have a way to handle this situation
<FromGitter> <kingsleyh> like with an alias or other such thing
<FromGitter> <jrei:matrix.org> here you can't
<FromGitter> <jrei:matrix.org> they use the same object
<FromGitter> <jrei:matrix.org> you'd have to sed into the files to rename it
<FromGitter> <kingsleyh> I just copy and paste for now and change some names
<FromGitter> <kingsleyh> they are both just 1 file each
<FromGitter> <kingsleyh> and decide which I like better
<FromGitter> <oprypin:matrix.org> @kingsleyh: make a writeup about it, im very curious
<FromGitter> <kingsleyh> Ok
<FromGitter> <oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org): lol i'm bisecting *something* but in fact i'm not getting the crash xD
<FromGitter> <oprypin:matrix.org> how is your success?
beefstar has joined #crystal-lang
beefstar has left #crystal-lang [#crystal-lang]
<FromGitter> <jrei:matrix.org> I definitely got segfaults
<FromGitter> <oprypin:matrix.org> good good
<FromGitter> <oprypin:matrix.org> my bisect finished but it got no results :D
<FromGitter> <jrei:matrix.org> it is finishing, my system slept 😅
<FromGitter> <jrei:matrix.org> I don't know why you didn't have a result, I'm on LLVM 10.0.1 too
<FromGitter> <jrei:matrix.org> is your crystal 0.35.1 statically linked?
<FromGitter> <oprypin:matrix.org> no'
<FromGitter> <jrei:matrix.org> mine yes
<FromGitter> <jrei:matrix.org> `ldd` said it is, but `file` not
<FromGitter> <jrei:matrix.org> it may have nothing to do, but that's one difference.
<FromGitter> <jrei:matrix.org> finally, got a result
<FromGitter> <oprypin:matrix.org> it's a bit of a weird result o.o
<straight-shoota> indeed
<straight-shoota> only semantic change is implementation of offsetof
<straight-shoota> and offsetof isn't even used in the compiler or stdlib
<FromGitter> <jrei:matrix.org> I'll run again, I think I messed up a bit
<FromGitter> <jrei:matrix.org> in my script I didn't have sh -e on first steps
<straight-shoota> but you can at least reduce the search range
<straight-shoota> for completeness, which exact LLVM version are you using?
<FromGitter> <jrei:matrix.org> LLVM 10.0.1
<straight-shoota> kay, so sayme as oprypin
<straight-shoota> *same
_ht has quit [Remote host closed the connection]
<FromGitter> <erdnaxeli:cervoi.se> how crystal tool expand is supposed to work?
<FromGitter> <erdnaxeli:cervoi.se> "crystal tool expand -c src/some/file.cr❌y src/some.cr" tells me there is nothing to expand
<FromGitter> <erdnaxeli:cervoi.se> well I have an error in my macro it seems, to the compiler printed it for me ^^
<FromGitter> <oprypin:matrix.org> nobody knows how to use it
<FromGitter> <erdnaxeli:cervoi.se> :(
<FromGitter> <Blacksmoke16> just add `{{debug}}` in you macro somewhere
<FromGitter> <erdnaxeli:cervoi.se> ah I always forgot about that, thanks
<FromGitter> <jrei:matrix.org> oprypin (https://matrix.to/#/@oprypin:matrix.org): now I have ".. was both good and bad"
<FromGitter> <jrei:matrix.org> I don't understand a thing...
<FromGitter> <oprypin:matrix.org> o.o
<FromGitter> <oprypin:matrix.org> can u just run through my command
<FromGitter> <oprypin:matrix.org> after `git bisect reset` of course
<FromGitter> <jrei:matrix.org> mine is similar, but ok
<FromGitter> <jrei:matrix.org> now I try to reproduce (again) on 0.36.1
<FromGitter> <jrei:matrix.org> I've a bisect.sh script. I'll try on LLVM 10, then LLVM 11
<FromGitter> <erdnaxeli:cervoi.se> calling a type "Union" is not a good idea :D
<FromGitter> <jrei:matrix.org> haha, you have to use `::Union` then
<straight-shoota> "both good and bad" *could* mean it doesn't fail always. Which would be really bad.
<straight-shoota> But most failing cases consistently reproduce, so it's unlikely
<straight-shoota> > haha, you have to use `::Union` then
<FromGitter> <jrei:matrix.org> like any already existing top-level object
<FromGitter> <jrei:matrix.org> (Array, Hash, etc)
<FromGitter> <jrei:matrix.org> ok, so got the crash with my posted commands using LLVM 11 - normal.
<FromGitter> <erdnaxeli:cervoi.se> Except that Union are used almost everywhere when you do "Something?"
<FromGitter> <erdnaxeli:cervoi.se> so you can very strange errors like this: https://carc.in/#/r/agah
<FromGitter> <erdnaxeli:cervoi.se> anyway, I figured it out quickly
<FromGitter> <erdnaxeli:cervoi.se> and it was just a bad name in a spec file
<FromGitter> <jrei:matrix.org> I was talking about placing it in a namespace
<FromGitter> <jrei:matrix.org> not overwriting the top-level definition
<FromGitter> <jrei:matrix.org> to be clear, like this: `struct Foo::Union; end`
<FromGitter> <erdnaxeli:cervoi.se> yes
<FromGitter> <jrei:matrix.org> oprypin (https://matrix.to/#/@oprypin:matrix.org) straight-shoota: I tried with LLVM 10 - cannot reproduce
<FromGitter> <oprypin:matrix.org> try llvm 11 with my script
<FromGitter> <jrei:matrix.org> LLVM 11 make it crash indeed
<FromGitter> <jrei:matrix.org> the issue is 0.35.1 supports only LLVM 10
<FromGitter> <oprypin:matrix.org> ok but like try with my script
<FromGitter> <jrei:matrix.org> ok ok
<FromGitter> <Blacksmoke16> Could you checkout the 0.35.1 tag, apply the llvm 11 patch, build, then use the resulting binary
<FromGitter> <oprypin:matrix.org> it skips versions that dont support llvm, worst case you'll bisect up to that llvm version
<FromGitter> <jrei:matrix.org> your script, or your command?
<FromGitter> <jrei:matrix.org> @Blacksmoke16: I thought of doing that, maybe that's "just" LLVM 11 not being fully supported
<FromGitter> <jrei:matrix.org> oprypin (https://matrix.to/#/@oprypin:matrix.org): I'm running https://github.com/crystal-lang/crystal/issues/10359#issuecomment-783574659
<straight-shoota> you could cherry pick #9829 on top of 0.35.1
hendursa1 has quit [Remote host closed the connection]
hendursa1 has joined #crystal-lang
<FromGitter> <jrei:matrix.org> got issues with the cherry pick
<FromGitter> <jrei:matrix.org> I'll try to figure out the conflicts.
<FromGitter> <jrei:matrix.org> I can integrate a commit just after 0.35.1?