jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | 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
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
oddp has quit [Ping timeout: 240 seconds]
<andremedeiros> friends, is there a way to do this in Crystal? https://pastebin.com/mxBKXiBQ
<andremedeiros> basically I'm looking for a way to pattern match the amount of parts into variables
<FromGitter> <Blacksmoke16> maybe with a tuple?
<andremedeiros> let me try this on a play url
<FromGitter> <Blacksmoke16> hm, idt it'll work
<FromGitter> <Blacksmoke16> prob better off just doing a case on `split.size`?
<andremedeiros> yup
<andremedeiros> shame tho, would be nice if this worked
<FromGitter> <wyhaines> Just changing you comparison to an array doesn't work? ⏎ ⏎ ```when [host, owner, name] then self.new(host, name, owner)``` ⏎ ⏎ ? [https://gitter.im/crystal-lang/crystal?at=5ef54c8cec4a341beeeca7cb]
<FromGitter> <Blacksmoke16> crystal doesnt have pattern matching, so idt so
<andremedeiros> not sure, I think I tried that, it complained about the variable not being found
<FromGitter> <Blacksmoke16> hm
<FromGitter> <Blacksmoke16> question
<FromGitter> <wyhaines> I assumed that host, owner, and name were either variables or methods.
<FromGitter> <Blacksmoke16> wouldnt it be better to just define 3 overloads
<FromGitter> <Blacksmoke16> for whatever obj you want to create
<FromGitter> <wyhaines> Because this works:
<andremedeiros> you probably hate this, but let me show you how this'd work in ruby
<FromGitter> <Blacksmoke16> yea idt thats possible
<FromGitter> <Blacksmoke16> at least as clean as that
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9btk prob best you can do afaik
<FromGitter> <Blacksmoke16> care to share what you plan on doing with this tho?
<FromGitter> <Blacksmoke16> might be a better way...
<andremedeiros> looks better than what I have, so I'll take it :-)
<andremedeiros> absolutely
<FromGitter> <wyhaines> Yeah. You are comparing the experimental pattern matching in current rubies to....not having that. ⏎ ⏎ The pattern matching is doing multiple things for you at the same time. You can get close using method overloading, and tuples.
<andremedeiros> I'm trying to match one of "name", "owner/name", "host/owner/name" into an instance of Repository
<andremedeiros> let me share the whole file with you
<FromGitter> <Blacksmoke16> im assuming the input string is dynamic? i.e. not a hard coded string
<andremedeiros> correct, it'll come from the command line
<andremedeiros> so a user would do something like "tool cd name" or "tool cd owner/name"
<andremedeiros> and this has to figure out what the user means
<FromGitter> <Blacksmoke16> meh, prob not going to get much better
<FromGitter> <Blacksmoke16> fwiw, you could do:
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ef555c8fa0c9221fc5eb4da]
<FromGitter> <Blacksmoke16> assuming its immutable, better off with a struct
<andremedeiros> sure is!
<andremedeiros> thank you!
Welog has quit [Ping timeout: 256 seconds]
<andremedeiros> still passes the spec too!
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ef5579b47fdfd21ede69277]
<FromGitter> <Blacksmoke16> id stick with what you did tho
<andremedeiros> also, I don't want to abuse your good will, but is there a better way to handle this? https://pastebin.com/8cuYbBj6
<andremedeiros> actually I quite like this
<FromGitter> <Blacksmoke16> its kinda meh
<FromGitter> <Blacksmoke16> overhead of the regex and could easily break
<FromGitter> <Blacksmoke16> why not just use option parser for everything?
<FromGitter> <Blacksmoke16> like
<FromGitter> <Blacksmoke16> i mean for handling commands and stuff, as it can do sub commands
<andremedeiros> oh snap
<FromGitter> <Blacksmoke16> idt it handles positional arguments, but should be easy enough to get
<FromGitter> <Blacksmoke16> like `ARGV[0]` or whatever
<FromGitter> <Blacksmoke16> there are also some shards out there for making cli apps that are more robust, might be worth checking out
<andremedeiros> has that landed in master yet?
<FromGitter> <Blacksmoke16> Should be released by now yea
<andremedeiros> i'm on 0.35.1 and it doesn't seem to care about the unprefixed "on" handlers
<FromGitter> <Blacksmoke16> Maybe look at the specs?
Welog has joined #crystal-lang
<andremedeiros> i'm looking at them and I can't understand how they pass
<FromGitter> <Blacksmoke16> Can you share what your trying with how your running it?
<andremedeiros> this seems to work on play
<andremedeiros> when I run that same code, I get https://pastebin.com/xGQacVSu
<andremedeiros> oh hold up
<andremedeiros> i was compiling with shards, which was picking up an older compiler
<FromGitter> <Blacksmoke16> Hm? Using shards build?
<andremedeiros> yeah "shards build"
<FromGitter> <Blacksmoke16> Gotcha
chachasmooth has quit [Ping timeout: 246 seconds]
chachasmooth has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 2.8]
DTZUZU has joined #crystal-lang
ghanima has joined #crystal-lang
alexherbo2 has joined #crystal-lang
svipal has quit [Ping timeout: 245 seconds]
<FromGitter> <jwaldrip> With GitHub actions, GitLab CI, and all the other alternatives... should crystal init still generate a travis.yml file?
<FromGitter> <aravindavk> @jwaldrip may be good for reference or reminder to use one CI. I felt similar when the default license file it created is MIT
<FromGitter> <jwaldrip> ooh, thats another one that can actually get you in trouble. Would hate to work for a private company and accidentally leave the MIT license
<FromGitter> <bararchy> Is Deque MT safe?
<FromGitter> <Daniel-Worrall> There's an open issue regarding the future of crystal initiative
<FromGitter> <Daniel-Worrall> Init*
Flipez has joined #crystal-lang
<FromGitter> <gdotdesign> anyone here run into an issue where the type checker didn't find the overloaded function although it has been defined?
HumanGeek has quit [Ping timeout: 256 seconds]
<yxhuvud> bararchy: no, it is not.
<yxhuvud> same as array.
oddp has joined #crystal-lang
HumanGeek has joined #crystal-lang
<FromGitter> <kingsleyh> how do I parse a unix epoch in ms to a Time? e.g. I have a string `1593163897.160700`
oddp has quit [Ping timeout: 256 seconds]
<jhass> >> Time.unix_ms(("1593163897.160700".to_f * 1000).to_i64)
<DeBot> jhass: # => 2020-06-26 09:31:37.160000000 UTC - https://carc.in/#/r/9bv8
<FromGitter> <asterite> @bararchy nothing is MT safe in the standard library except Channel
<FromGitter> <asterite> andremedeiros: `case array.size; when 1; ...; when 2; ...; when 3; end`. Pattern matching is a nice to have but not necessary at all
oddp has joined #crystal-lang
<sorcus> Hi everyone :-)
<FromGitter> <Blacksmoke16> o/
<raz> o/
<sorcus> Little question. If i write `foo = BigInt.new "12345"` - it's converted to BigInt once? Even if i use `foo` many times?
<FromGitter> <Blacksmoke16> yea, `foo` would be an instance of `BigInt`, just like any other struct/class
<sorcus> Thanks Blacksmoke16 :-)
HumanGeek has quit [Ping timeout: 246 seconds]
HumanGeek has joined #crystal-lang
HumanGeek has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
<FromGitter> <DisjoinedBrute> Can anyone help me out https://forum.crystal-lang.org/t/compilation-error-in-crystal-0-35-1/2283
<FromGitter> <Blacksmoke16> > Try clearing the cache: `rm -rf ~/.cache/crystal`.
<FromGitter> <DisjoinedBrute> oh wow that worked
<FromGitter> <DisjoinedBrute> thanks
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <Blacksmoke16> prob got corrupted or something during the upgrade
<FromGitter> <DisjoinedBrute> oh makes sense
<oprypin> damn if this has been so easy to reproduce for so many people, why not follow up on the cache stuff
<FromGitter> <j8r> IIRC https://github.com/crystal-lang/crystal/blob/476486e0a/src/array.cr#L2071 means the array capacity is doubled when there is no more room?
<FromGitter> <j8r> it means, 1 -> 2 -> 4 -> 8 etc?
lunarkitty has quit [Ping timeout: 272 seconds]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 264 seconds]
lunarkitty has joined #crystal-lang
twosecslater has left #crystal-lang [#crystal-lang]
<FromGitter> <watzon> Seems like the problem is that no one can agree on the right action to take @oprypin
<FromGitter> <watzon> It would be nice to have fixed though. I've had that issue several times.
HumanG33k has joined #crystal-lang
twosecslater has joined #crystal-lang
<FromGitter> <kazzkiq> Hello
<FromGitter> <kazzkiq> Is there any impact on using a single `require "../etc/*"` instead of multiple `require "../etc/1"`, etc?
<FromGitter> <Blacksmoke16> can run into issues using the former, as they're required in abc order
<FromGitter> <Blacksmoke16> depends on the context of which I use
<FromGitter> <kazzkiq> Say I have a `helpers` folder with 20 files. But for sake of productivity just want to `require "../helpers/*"` on every file and be done with it
<FromGitter> <Blacksmoke16> assuming they're all independent files prob would be fine
<FromGitter> <tenebrousedge> ^
<FromGitter> <Blacksmoke16> mainly run into issues when some depend on others and arent required first, i.e. one defines an abstract class the other inherit from
<FromGitter> <tenebrousedge> or you could explicitly define the order in some file and require that
<FromGitter> <kazzkiq> But wouldn't it impact performance? I'm guessing Crystal already does the job of ignoring required files which are not used, etc.
<FromGitter> <tenebrousedge> it has a 0% chance of impacting performance
<FromGitter> <tenebrousedge> Crystal is a compiled language
<FromGitter> <tenebrousedge> require happens at compile time, not runtime
<FromGitter> <kazzkiq> I'm more about compiling time performance. By requiring `*` on every file, perhaps my project would take longer to compile
<FromGitter> <kazzkiq> I have no idea tho, just guessing if it could bite me in the long run
<FromGitter> <tenebrousedge> generally I ignore performance until I'm forced to do otherwise, and it's difficult to envision the circumstances under which I would care about compilation performance
<FromGitter> <tenebrousedge> Crystal itself is a fairly large and complex project, it compiles in a reasonable time frame, and probably your project will not be worse than Crystal
<FromGitter> <tenebrousedge> if at some point that becomes not true, it's probably worth congratulations
<FromGitter> <watzon> It can and will impact compile time performance, but there's really no way around that. You won't get around it by requiring files manually,
<FromGitter> <watzon> What affects the compile time performance is just the fact that you're requiring those files in the first place
<oprypin> watzon, regarding earlier, no nobody knows what the problem is and hence definitely not the solution. the disagreement is on what level of blind workarounds is applicable
<oprypin> kazzkiq, require what you use, then order will never be important
<oprypin> if each file directly requires only files that it needs
<oprypin> with asterisks you very easily add circular dependencies and those can randomly stop working
<FromGitter> <watzon> Truth. I've had this happen in larger projects.
<oprypin> kazzkiq, regarding performance, a file is required only once. you can imagine a crystal program as a huge single file, and when a particular file is `require`d *for the first time*, it gets pasted in there
<oprypin> so unless you otherwise would've never required that file at all, this should be totally fine. just that the other reason to not use `*` is already more than enough
<FromGitter> <asterite> oprypin: with the cache issue, I feel like catching those errors, cleaning the cache and trying again is a good workaround for now. Unfortunately the rest of the core team prefers to let it crash until we have time to figure out why it crashes. Meanwhile it affects a lot of developers and it makes them unhappy. So even if I sent a PR to "fix" it it won't be accepted.
<FromGitter> <j8r> There is a legit case of crash with an invalid cache: aborting in a middle of a compilation
<oprypin> put up a full step by step repro then
<oprypin> never happened to me
<FromGitter> <asterite> the thing is that it's a race condition so it's hard to reproduce
<oprypin> is it really? it's always connected to upgrades of crystal and such, doess it need to *also* have a race condition?
<FromGitter> <j8r> Maybe I cancel when there is a linking, or during the generation of .o files
<oprypin> asterite, i dont know if i'd count that as a repro :/ it's not showing the root cause
<oprypin> just another way to show that sympton
<oprypin> m
<FromGitter> <j8r> lol maybe something like ⏎ ⏎ ```while sleep 3; do ⏎ crystal eval "StaticArray(Int32, 4096).new 0" & ⏎ sleep 1 ⏎ done``` ⏎ ⏎ Warning: prepare to do a CTRL+D and clean your cache [https://gitter.im/crystal-lang/crystal?at=5ef64930613d3b33940de625]
<FromGitter> <j8r> that's not really what I do in real life
<FromGitter> <j8r> I still have to figure out how to stop the compiler at the right time
<FromGitter> <asterite> Here's the fix: https://github.com/crystal-lang/crystal/pull/9554
<FromGitter> <asterite> oprypin: the root cause is stopping compilation and having an `.o` file with half of the contents it supposed to have. This is hard to reproduce because you have to `ctrl+c` in the right moment, but it's the same as just putting garbage inside an existing `.o` file
<FromGitter> <asterite> That is, we can't prevent users from messing around with the cached object files. But we can clear those things and try again because it's harmless to do so.
alexherbo29 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
alexherbo29 is now known as alexherbo2
<FromGitter> <j8r> I found a simple way to crash
<FromGitter> <j8r> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ef6533e405be935cdc4d5c0]
<FromGitter> <j8r> the two same commands, ran nearly at the same time
<FromGitter> <j8r> hum no, that's not really cache - more missing files
<FromGitter> <j8r> I give up, too hard to consistently reproduce x.x
<FromGitter> <watzon> Heh
<FromGitter> <tenebrousedge> neat
<FromGitter> <Blacksmoke16> need some of that AA :P
<FromGitter> <Blacksmoke16> is it expected that you can use a module to define a `.class` restriction?
<FromGitter> <tenebrousedge> does it work?
<FromGitter> <tenebrousedge> I think I would expect that to work
<FromGitter> <Blacksmoke16> sorry, `that you cant*`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9c00
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9c02 or with `extend`
<FromGitter> <tenebrousedge> I think that if that shouldn't work, I'd want to know why
<FromGitter> <tenebrousedge> but I have no idea if that's a bug
<oprypin> Blacksmoke16, ok well extend is different https://play.crystal-lang.org/#/r/9c04
<FromGitter> <Blacksmoke16> :0 oo good call
<oprypin> yea i guess it doesnt work for modules like that
<FromGitter> <Blacksmoke16> i think i can work with that
twosecslater has left #crystal-lang [#crystal-lang]
twosecslater has joined #crystal-lang
twosecslater has left #crystal-lang [#crystal-lang]
twosecslater has joined #crystal-lang
<FromGitter> <asterite> oprypin: see? I fixed it but it won't be accepted :-*
<FromGitter> <asterite> :-(
rocx has joined #crystal-lang
rocx_ has quit [Quit: 👏 developers 👏 developers 👏 developers 👏 developers]
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo2 has joined #crystal-lang
<FromGitter> <z64> hey all - ⏎ we just upgraded our whole stack to 0.35.1 and are seeing *exponentially* longer compile times when building in the official docker images vs host, with on various scales of code examples ⏎ the following are traces from building an empty web scaffold with `--release` ⏎ https://paste.sr.ht/~z64/738cd51d07894bb7a97597f0a6464f9c8fece518 ⏎ ... [https://gitte
<FromGitter> ... r.im/crystal-lang/crystal?at=5ef65f9747fdfd21ede9373f]
<FromGitter> <z64> it happens in bc+obj codegen phase, i had wondered if it was maybe some odd interaction with llvm 8 in 0.35, but our other dev who is using llvm 8 doesn't have the issue on his host
<oprypin> z64, care to bisect it? or is it just docker images
<FromGitter> <z64> i can build our prod app in release just fine on my host in reasonable time - the codegen overhead is only observed in the official docker images
<FromGitter> <z64> in the container, the compiler is continuing to run at 100% cpu util the whole time
<straight-shoota> so what's the difference between host and docker image?
<straight-shoota> target triple, llvm version?
<FromGitter> <z64> read the paste; crystal -v of the containers i've tried and my host are shown ⏎ coworker who has llvm 8 is on the same target triple
ghanima has quit [Ping timeout: 240 seconds]
<FromGitter> <asterite> maybe memory issue so there's a lot of swap
<FromGitter> <dscottboggs_gitlab> is this supposed to b e this way? https://carc.in/#/r/9c0b
<oprypin> dscottboggs_gitlab, are u intentionally making it confuse the T s
<FromGitter> <dscottboggs_gitlab> yes
<FromGitter> <dscottboggs_gitlab> I want to reopen Two from within Klass
<oprypin> what
<FromGitter> <dscottboggs_gitlab> 😂 so that's not a supported feature then?
<oprypin> dscottboggs_gitlab, no like why are you naming your class T
<oprypin> of course it's not supported
<oprypin> https://carc.in/#/r/9c0c much better
Nekka has quit [Ping timeout: 260 seconds]
<FromGitter> <dscottboggs_gitlab> Because I want to add a method to `T` where `T` is the value passed to `Klass(T)`
<oprypin> no
<FromGitter> <dscottboggs_gitlab> https://carc.in/#/r/9c0e
<oprypin> good
<FromGitter> <dscottboggs_gitlab> The use-case being where `Klass` is an included module and `test` is an abstract method
Nekka has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
HumanG33k has quit [Quit: Leaving]
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` ⏎ ⏎ why? [https://gitter.im/crystal-lang/crystal?at=5ef6751bec4a341beeef9f9e]
<FromGitter> <Blacksmoke16> try `T.has_method? :zero`
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
alexherbo2 has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
DTZUZU_ has joined #crystal-lang
HumanG33k has joined #crystal-lang
DTZUZU has quit [Ping timeout: 265 seconds]
<FromGitter> <dscottboggs_gitlab> Thanks @Blacksmoke16, I'll try that.
<FromGitter> <dscottboggs_gitlab> Why doesn't this work though? https://carc.in/#/r/9c0w
<FromGitter> <Blacksmoke16> https://carc.in/#/r/9c10
<FromGitter> <Blacksmoke16> you want `extend`, guess defining it as `self.result` doesnt matter
<FromGitter> <dscottboggs_gitlab> Sorry, my bad, here's a more clear example https://carc.in/#/r/9c15
<FromGitter> <Blacksmoke16> https://carc.in/#/r/9c19
<FromGitter> <Blacksmoke16> you want both `include` and `extend`
<FromGitter> <Blacksmoke16> but thats prob a bit of a smell...
<FromGitter> <Blacksmoke16> main issue is your module defines a method that is used at instance level, and at class leve
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang