RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.1 | 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
devil_tux has joined #crystal-lang
<FromGitter> <tenebrousedge> Okay, so I have a dumb and don't understand the type system well enough to tell the compiler what my Proc types are ⏎ https://play.crystal-lang.org/#/r/6kqb ⏎ I've been trying to put `.as(various_things)` in various places. I think next time I'll just write out real methods :/
<FromGitter> <Blacksmoke16> `(k : String, j : String)` i think you just have to specify the types, not the keys
<FromGitter> <Blacksmoke16> nvm, wrong context
<FromGitter> <Blacksmoke16> have you read the docs on procs?
<FromGitter> <tenebrousedge> I did, they mentioned overloading, but it's not really clear what's supposed to happen here. this issue (https://github.com/crystal-lang/crystal/issues/3454) also mentioned them, but I'm still not clear
<FromGitter> <Blacksmoke16> that hurts my brain
<FromGitter> <Blacksmoke16> i dont have an answer solution atm :P
<FromGitter> <johnjansen> thats some ugly code
<FromGitter> <tenebrousedge> well, it's just a benchmark, there isn't any point to using procs other
<FromGitter> <dscottboggs_gitlab> > there isn't any point to using procs other ⏎ ⏎ Then use defs....please lol
<FromGitter> <dscottboggs_gitlab> also prefer do..end blocks over curly braces when it's long or nested
<FromGitter> <johnjansen> YES, i was just about to say, no harm in formatting it nicely
<FromGitter> <tenebrousedge> I didn't realize that using Procs was supposed to be difficult
<FromGitter> <dscottboggs_gitlab> I'm literally reformatting it in my text editor just to figure out what is going on
<FromGitter> <johnjansen> so am I
<FromGitter> <johnjansen> lol
<FromGitter> <tenebrousedge> keep the compliments coming
<FromGitter> <Blacksmoke16> i mean its not really *difficult* just that when they are so nested like that its hard to understand what is going on to solve the problem
<FromGitter> <dscottboggs_gitlab> it's not that... it's just that the syntax for them is not super readable, especially the way you have like nested curly-brace blocks on the same line
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16 says the guy who writes PHP for a living 😆
<FromGitter> <Blacksmoke16> hey now, PHP synatx isn't *that* bad ;)
<FromGitter> <dscottboggs_gitlab> it's like.. the go-to example of "ugly but it works so fuck it"
<FromGitter> <tenebrousedge> this code would have been discarded already if it worked. I'd just like to know what sort of type coercion is supposed to be happening here
<FromGitter> <dscottboggs_gitlab> ok but for real I'm baffled as to why his code isn't working https://play.crystal-lang.org/#/r/6kqw
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <dscottboggs_gitlab> all th types line up
<FromGitter> <dscottboggs_gitlab> AHH I GOT IT
<FromGitter> <dscottboggs_gitlab> So you can't specify a return type restriction on a proc literal
<FromGitter> <Blacksmoke16> where does that happen?
<FromGitter> <dscottboggs_gitlab> I.E. `->(String, String) : Int32` doesn't mean *a proc that accepts two strings and returns an integer*, it's a syntax error.
<FromGitter> <dscottboggs_gitlab> it doesn't it's just tangential
<FromGitter> <Blacksmoke16> but where does he do that?
<FromGitter> <Blacksmoke16> only type restrictions i see are for params
<FromGitter> <dscottboggs_gitlab> he doesn't just a sec I'm trying to make a point
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <dscottboggs_gitlab> HOWEVER, when you create a proc like `->(some : String) { some code that returns an Int32 }` the resulting TYPE is a `Proc(String, Int32)` so... https://play.crystal-lang.org/#/r/6kr8
<FromGitter> <Blacksmoke16> ah nice, good catch
<FromGitter> <dscottboggs_gitlab> sorry I didn't mean to get snippy
<FromGitter> <dscottboggs_gitlab> thanks
<FromGitter> <Blacksmoke16> so in reality the error was from the proc expecting a string as a param and returning a string
<FromGitter> <Blacksmoke16> not accepting two strings
<FromGitter> <dscottboggs_gitlab> no it was the fact that the syntax for proc literals and for the proc type restrictions and procs as a generic are all different and kinda confusing
<FromGitter> <Blacksmoke16> well yea `Proc(String, String)` means String as arg and returns string
<FromGitter> <Blacksmoke16> which doesnt match with his two string args and return `Int32`
<FromGitter> <tenebrousedge> well, I'm certainly very confused, but I appreciate everyone's efforts. Thank you very much. I will study this until it makes more sense
<FromGitter> <dscottboggs_gitlab> like `->(String, String) : Int32` is the same (in the context of a type restriction as `Proc(String, String, Int32)` which is to say an instance of the proc generic class with the T values String, String, and Int32.
<FromGitter> <dscottboggs_gitlab> I find this very confusing
<FromGitter> <dscottboggs_gitlab> and apparently it's an issue with newcomers in general.
<FromGitter> <johnjansen> honestly, i would have started with a simpler bit of code though
<FromGitter> <Blacksmoke16> go big or go home :P
<FromGitter> <Blacksmoke16> i ran into 2 compiler bugs and it kinda halted my dev
<FromGitter> <Blacksmoke16> rip
<FromGitter> <dscottboggs_gitlab> oh no :(
<FromGitter> <dscottboggs_gitlab> you can't fix them?
<FromGitter> <Blacksmoke16> #7584 #7583
<FromGitter> <Blacksmoke16> Ill try to work around them but dont really have any ideas atm
<FromGitter> <dscottboggs_gitlab> well in order to track it down the first thing you'll need is a version of the compiler that isn't compiled with `--static`
<FromGitter> <dscottboggs_gitlab> that's why you've got all the `???`s
<FromGitter> <dscottboggs_gitlab> which... good luck, that thing is HUGE
<FromGitter> <Blacksmoke16> my only hope is asterite coming along and being like `oh yea thats due to blah blah blah, ill make a PR real quick` :P
<FromGitter> <dscottboggs_gitlab> I don't even think my server rack would compile the crystal compiler
<FromGitter> <dscottboggs_gitlab> hahaha right? Love it when he does that
<FromGitter> <Blacksmoke16> what like build it locally?
<FromGitter> <dscottboggs_gitlab> or like "oh hey, so-and-so can fix this. Hey @so-and-so come fix this!" haha
<FromGitter> <dscottboggs_gitlab> > build it locally ⏎ ⏎ yes
<FromGitter> <dscottboggs_gitlab> well... the server could do it, I don't think my hard drives could...
<FromGitter> <dscottboggs_gitlab> the last time I had money for drives they were a lot more expensive than they are now :/
<FromGitter> <Blacksmoke16> well now i got a diff error
<FromGitter> <Blacksmoke16> :S
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9841f03dd8171149480c6e]
<FromGitter> <Blacksmoke16> prob related to the `<=>` change
<FromGitter> <dscottboggs_gitlab> `<=>` changed?
<FromGitter> <Blacksmoke16> oh i can fix this, sec
<FromGitter> <johnjansen> @Blacksmoke16 BTW line 19, its either a class or an instance …
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <johnjansen> `when PathParam` but `p` is an Instance
<FromGitter> <Blacksmoke16> yea so?
<FromGitter> <Blacksmoke16> very bottom of page
<FromGitter> <johnjansen> ok, ignore me …
<FromGitter> <Blacksmoke16> is pretty slick
<FromGitter> <dscottboggs_gitlab> indeed!
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9844099d9cc8114a17e177]
<FromGitter> <dscottboggs_gitlab> nice that there's docs for that
<FromGitter> <dscottboggs_gitlab> I should re-read the book sometime, or like review the changes to it at least
<FromGitter> <Blacksmoke16> prob not a bad idea tbh
<FromGitter> <Blacksmoke16> i keep meaning to do an annotation section but haven't gotten around to it yet
<FromGitter> <dscottboggs_gitlab> That was how I started with crystal. I read almost the whole book front-to-back before ever writing any code.
<FromGitter> <Blacksmoke16> super helpful
<FromGitter> <johnjansen> a little “magic” for my liking, but yes … anyhoo, changing the structure slightly results in a more likely candidate ```undefined method 'segment_index' for PathParam(T).class```
<FromGitter> <Blacksmoke16> change to what?
<FromGitter> <johnjansen> i was explicit about the class matching
<FromGitter> <dscottboggs_gitlab> `when .is_a? Klass then...` instead of `when Klass`?
<FromGitter> <johnjansen> `case p.class`
<FromGitter> <Blacksmoke16> rip https://play.crystal-lang.org/#/r/6kri
<FromGitter> <dscottboggs_gitlab> wouldn't that compare to p.class.class due to the aforementioned magic?
<FromGitter> <Blacksmoke16> error message makes sense, since there is no `self.segment_index` on `PathParam` type
<FromGitter> <Blacksmoke16> ye ^
<FromGitter> <Blacksmoke16> basic any time i get past downcast error i get hit with `no target defs`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6krl
<FromGitter> <dscottboggs_gitlab> wait...so your bug only applies to an empty array?
<FromGitter> <dscottboggs_gitlab> ejsy og oy
<FromGitter> <johnjansen> @Blacksmoke16 what are you expecting `p` to be within the `then`
<FromGitter> <Blacksmoke16> an instance of `PathParam` from the `.each` block
<FromGitter> <dscottboggs_gitlab> ok. so I'm super confused. lemme walk you through why
<FromGitter> <johnjansen> SORRY, i just realized i pasted the wrong error ⏎ ⏎ ```undefined method 'segment_index' for Param+``` [https://gitter.im/crystal-lang/crystal?at=5c9845cc52c7a91455eec218]
<FromGitter> <dscottboggs_gitlab> oh nope I'm not confused
<FromGitter> <johnjansen> the compiler error relates to the “magic” im not that fond of
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab sorry, error happens with empty array, or more than one when block https://play.crystal-lang.org/#/r/6krt
<FromGitter> <Blacksmoke16> ill update issues to explain some of what we chatted about
<FromGitter> <dscottboggs_gitlab> try it with `.responds_to?` instead
<FromGitter> <Blacksmoke16> this code should work
<FromGitter> <Blacksmoke16> compiler should know the type of `p` when its in the matching case block
<FromGitter> <dscottboggs_gitlab> (as a workaround, when I've used it it seemed to be more straightforward)
<FromGitter> <dscottboggs_gitlab> These sorts of bugs have started coming around sometimes since they started automatically upcasting to `+` types a few versions ago as an optimization...
<FromGitter> <dscottboggs_gitlab> I would think this would work: https://play.crystal-lang.org/#/r/6krw
<FromGitter> <dscottboggs_gitlab> also, like the error literally tells you its a compiler bug, you need to track that down in the compiler
<FromGitter> <dscottboggs_gitlab> have you tried searching for the string "no target defs" in the source?
<FromGitter> <Blacksmoke16> i added a better stack trace
<FromGitter> <dscottboggs_gitlab> oh I see
<FromGitter> <dscottboggs_gitlab> ayyy now you're on to something
<FromGitter> <dscottboggs_gitlab> see, the fact that the compiler code we're looking at doesn't look like some insane esoteric nonsense is one of the biggest reasons I got so into Crystal... sure there's some hacky stuff but as far as syntax goes it's clean all the way down
<FromGitter> <dscottboggs_gitlab> if only we had decent debugging support
<FromGitter> <Blacksmoke16> let me see what `node` is
<FromGitter> <Blacksmoke16> the hell
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c984882fcaf7b5f730d38b0]
<FromGitter> <johnjansen> ```Foo.new.call [] of PathParam(String) # added String``` ⏎ ⏎ you arent passing a type [https://gitter.im/crystal-lang/crystal?at=5c98489a9d9cc8114a17f940]
<FromGitter> <dscottboggs_gitlab> what
<FromGitter> <johnjansen> ``````
<FromGitter> <Blacksmoke16> yea i dont have to pass a type for `Param`
<FromGitter> <Blacksmoke16> generic type
<FromGitter> <dscottboggs_gitlab> I'm still hung up on what data type Call is and where that comes from
<FromGitter> <dscottboggs_gitlab> > let me see what `node` is ⏎ ^^
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c98492b3dd817114948323e]
<FromGitter> <Blacksmoke16> yea thats what it printed
<FromGitter> <Blacksmoke16> `(["", "foo", "123"] of String)[p.segment_index]`
<FromGitter> <Blacksmoke16> node is that string array
<FromGitter> <dscottboggs_gitlab> um
* FromGitter * dscottboggs_gitlab is out
<FromGitter> <Blacksmoke16> :S
<FromGitter> <Blacksmoke16> wait you see how its just printing p?
<FromGitter> <Blacksmoke16> not like `p.segment_index`
<FromGitter> <elorest> Is there any formal convention about where in a file requires go? It seems wrong to put them after code in a file.
<FromGitter> <dscottboggs_gitlab> sometimes you need to @elorest
<FromGitter> <dscottboggs_gitlab> but generally it's better to have them at the top of the file so you can quickly see them
<FromGitter> <elorest> Definitely but in pretty much every one of those situations you could have separated that code out into a separate file and required it as well.
<FromGitter> <elorest> Debating that right now lol
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab https://play.crystal-lang.org/#/r/6ks0
<FromGitter> <Blacksmoke16> setting `p.segment_index` to local var first works
<FromGitter> <dscottboggs_gitlab> oof
<FromGitter> <dscottboggs_gitlab> yup that's a bug right there
<FromGitter> <Blacksmoke16> indeed
<FromGitter> <dscottboggs_gitlab> best to let the core team wake up and take a look at it I think
<FromGitter> <Blacksmoke16> yea i added some findings to the issue, see what their thoughts are
<FromGitter> <dscottboggs_gitlab> at least you have a workaround
<FromGitter> <Blacksmoke16> for that at least
<FromGitter> <Blacksmoke16> gotta find one that works for both downcast and target defs bugs :p
<FromGitter> <dscottboggs_gitlab> oh god I'm gonna be so tired at work tomorrow.
<FromGitter> <dscottboggs_gitlab> Peace
<FromGitter> <Blacksmoke16> o/
<FromGitter> <Blacksmoke16> imma get to bed too
f1refly has quit [Ping timeout: 240 seconds]
Kixune has joined #crystal-lang
f1refly has joined #crystal-lang
chemist69 has quit [Ping timeout: 240 seconds]
chemist69 has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
devil_tux has quit [Ping timeout: 255 seconds]
Kixune has quit [Quit: Kixune]
Kixune has joined #crystal-lang
Kixune has quit [Quit: Kixune]
return0e has quit [Read error: Connection reset by peer]
return0e_ has joined #crystal-lang
<FromGitter> <gdotdesign> anyone knows why this branch collapses into the parent type if more than two siblings are specified? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c98877f2fb6800d8078ec82]
return0e has joined #crystal-lang
return0e_ has quit [Ping timeout: 245 seconds]
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
return0e_ has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
marmotini_ has joined #crystal-lang
ashirase has quit [Ping timeout: 250 seconds]
hoffentlichja has joined #crystal-lang
<hoffentlichja> Hi. How can I do a regex match on a Char? there's no .match method
<FromGitter> <bew> what kind of regex check you want to do?
<hoffentlichja> something that looks like this in ruby: "some long mixed string".chars.select { |char| char.match?(/[a-zA-z]+/) }
<FromGitter> <bew> the `+` doesn't make sense, a Char is a single character
<FromGitter> <bew> if you want to check if the char is a letter, you could do `char.letter?`
<hoffentlichja> yes a small mistake
<FromGitter> <bew> there is also for a kinda-regex check: https://crystal-lang.org/api/0.27.2/Char.html#in_set%3F(*sets%3AString)-instance-method
<hoffentlichja> I didn't know about letter?, but what about other kind of matches for other characters?
<hoffentlichja> oh I see, the link seems to answer the question
<FromGitter> <bew> :)
<hoffentlichja> thanks
return0e has joined #crystal-lang
return0e_ has quit [Ping timeout: 250 seconds]
marmotini has joined #crystal-lang
marmotini_ has quit [Ping timeout: 246 seconds]
marmotini_ has joined #crystal-lang
marmotini has quit [Ping timeout: 250 seconds]
ashirase has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
marmotini has joined #crystal-lang
marmotini_ has quit [Ping timeout: 245 seconds]
marmotini_ has joined #crystal-lang
marmotini has quit [Ping timeout: 246 seconds]
marmotini_ has quit [Ping timeout: 245 seconds]
<wuehlmaus> icr doesn't build here throwing an error at Time.now
<wuehlmaus> in src/icr/cli.cr:45: undefined method 'now' for Time.class (did you mean 'new'?)
<FromGitter> <Blacksmoke16> `Time.now` should be a thing
<FromGitter> <dscottboggs_gitlab> what version of crystal do you have @wuehlaus
<FromGitter> <dscottboggs_gitlab> that's super wierd
<wuehlmaus> the git version
<wuehlmaus> Crystal 0.28.0-dev [3286e11f5] (2019-03-23)
<wuehlmaus> and as i was unsure in mangled something i did a fresh git clone
<wuehlmaus> i uncommented #check_for_update unless update_check_disabled
<wuehlmaus> then icr builds
<FromGitter> <tenebrousedge> Not the only weird issue with .28.0-dev (https://github.com/crystal-lang/crystal/issues/7577#issuecomment-475845401)
<FromGitter> <straight-shoota> wuehlmaus, `Time.now` was removed in #5346. You should use either `Time.local` or `Time.utc` instead
<FromGitter> <Blacksmoke16> oh, that would do it
<FromGitter> <straight-shoota> => https://github.com/crystal-lang/crystal/pull/7586
<FromGitter> <j8r> one should add a comment about why the issue is closed https://github.com/crystal-lang/crystal/issues/1388#issuecomment-476166273. ⏎ I personally understand why, and that the pipe operator design doesn't fit to Crystal. Other may not understand
<FromGitter> <j8r> Perhaps give examples too like `"Elixir Rocks" |> String.upcase |> String.split # => ["ELIXIR", "ROCKS"]` translates to `"Elixir Rocks".upcase.split # => ["ELIXIR", "ROCKS"]`
asterite has quit [Ping timeout: 268 seconds]
jhass has quit [Ping timeout: 264 seconds]
jhass has joined #crystal-lang
asterite has joined #crystal-lang
<FromGitter> <yxhuvud> Ruby handled it by adding `.then` instead of adding new syntax. Perhaps that could be a better way?
<hoffentlichja> what's the equivalent of Ruby's .instance_variables ?
<FromGitter> <Blacksmoke16> can get it via macro `{{@type.instance_vars}}`, but only works in context of a method
<hoffentlichja> I see
<robacarp> and it only works in macro land (not runtime)
<robacarp> @Blacksmoke16 can't you reference it outside a method by starting with a https://crystal-lang.org/api/0.27.2/Crystal/Macros/TypeNode.html ?
<FromGitter> <Blacksmoke16> you could make a macro that build out a runtime method
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> robacarp, i dont thinkso?
<FromGitter> <Blacksmoke16> https://carc.in/#/r/6evk
<FromGitter> <Blacksmoke16> hoffentlichja https://carc.in/#/r/6kvu
<robacarp> heh, I was just tinkering with this https://carc.in/#/r/6kvv
<FromGitter> <Blacksmoke16> yea is my most wanted feature atm
<FromGitter> <Blacksmoke16> as currently is no way to build out methods w/o a macro
<FromGitter> <Blacksmoke16> i.e. read an annotation off an ivar, then override its getter based on data from the annotation
<robacarp> sure, because you need to declare the methods at compile time
<FromGitter> <Blacksmoke16> i mean like `macro has_one`
<robacarp> yeah
<FromGitter> <Blacksmoke16> vs just iterating over ivars and building stuff out like https://carc.in/#/r/6kvx
<FromGitter> <Blacksmoke16> ```@[OneToOne] ⏎ property user : User``` [https://gitter.im/crystal-lang/crystal?at=5c98e121dfc69a1454f241a3]
<FromGitter> <Blacksmoke16> which would define like ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5c98e12cd0133e21e5122401]
<FromGitter> <Blacksmoke16> ```def user ⏎ User.find @id ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c98e145a21ce51a20bbb4b5]
<FromGitter> <Blacksmoke16> or something along those lines
<robacarp> yeah, that's why I opted to have mosquito declare all parameters at once
<FromGitter> <Blacksmoke16> maybe one day
<FromGitter> <Blacksmoke16> would make associations easier imo, only one syntax that is used everywhere
<FromGitter> <Blacksmoke16> then optional fields on annotation for like pk/fk et
<FromGitter> <r00ster91> functions from C that I use in my code, will the code of those functions be optimized too when I compile with `--release`?
<FromGitter> <r00ster91> For example when a check is done in a C function and I do this check in my code too, will there be only 1 check?
<FromGitter> <j8r> what do people think of https://carc.in/#/r/6kvy (that's really an imperfect POC)
<z64> i don't know what you mean by a "check", but no, the compiler has no idea what your C functions do. they are already compiled, and simply linked against after crystal compiles your program
<FromGitter> <j8r> This make this work: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c98e8abdfc69a1454f27422]
<FromGitter> <r00ster91> ooh.. so LLVM doesn't have access to the code of the functions. But that also makes sense since they are already compiled and binary.
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <yxhuvud> z64: could there be some link time optimization though?
<z64> i dont think its the kind of optimization they were asking about
<FromGitter> <yxhuvud> I'm not totally certain how intrusive LTO can be. It might be possible that it is smart enough to handle reasonably simple cases like that.
<FromGitter> <girng> Good morning!!
<FromGitter> <r00ster91> good afternoon
<FromGitter> <sam0x17> is 0.27.1+ still not working in alpine or is that fixed now?
<FromGitter> <straight-shoota> @sam0x17 There have been several issues on alpine, but 0.27.2 should be working
<FromGitter> <j8r> 1) 27.2 is working yes
<FromGitter> <straight-shoota> It's available in aports
<FromGitter> <j8r> I have ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c98f5e48aa66959b66c3f09]
<FromGitter> <Maroo-b> Hello, ⏎ I'm working on this issue: https://github.com/crystal-lang/crystal/issues/6040 and I'm asking if someone knows which file to work on, I tried to debug with `puts` statements but it was too verbose and I didn't manage to find the source yet. ⏎ Should I look in https://github.com/crystal-lang/crystal/tree/master/src/compiler/crystal/semantic ⏎ or https://gith
<FromGitter> ... ub.com/crystal-lang/crystal/blob/master/src/compiler/crystal/syntax/parser.cr ? ⏎ Thanks :) [https://gitter.im/crystal-lang/crystal?at=5c98f6df8aa66959b66c47b3]
<FromGitter> <straight-shoota> @Maroo-b That's a semantic issue
<FromGitter> <Maroo-b> cool thanks @straight-shoota , just curious do you have any tips for debugging the compiler, I mean except of using `puts` statements :D
<FromGitter> <straight-shoota> Hm, this is not really a classical debugging scenario. The status quo is intended and correct, it's just that the proposed alternative would be more consistent. So I don't think you'll need much debug info about the status of variables. You should look at the code handling procs and closures and how `typeof` is implemented.
<FromGitter> <straight-shoota> I'm not familiar with this part, so I can't point you to a more specific location
<mps> sam0x17: crystal 0.27.0 is in Alpine stable release (v3.9) and 0.27.2 is in edge (development,testing)
<FromGitter> <straight-shoota> Oh and this issue is super low priority, because it's not really a bug and very unlikely to happen. So don't dig yourself in too deep ;)
<FromGitter> <Maroo-b> hhhh ok, I spent some time last night on it, as I mentioned using `puts` statement to inspect is really hard with the compiler. ⏎ I'll work on something else then :)
<FromGitter> <straight-shoota> Yeah, there is more low hanging fruit
DTZUZU has quit [Quit: WeeChat 2.2]
DTZUZU has joined #crystal-lang
<FromGitter> <silmanduin66> if i have a text.txt file like that : ⏎ ⏎ ```"name1" ⏎ "name2" ⏎ ...``` [https://gitter.im/crystal-lang/crystal?at=5c990156f3dbbd230cb60a14]
<FromGitter> <j8r> Easy @silmanduin66 https://carc.in/#/r/6kwe
<FromGitter> <silmanduin66> thanks
<FromGitter> <girng> @j8r 👍
knstn has joined #crystal-lang
<knstn> Is Crystal for Ruby, what is Cython for Python in a way?
lucasb has joined #crystal-lang
<FromGitter> <alex-lairan> @knstn no, Crystal is a standalone language.
<FromGitter> <alex-lairan> With CRSFML, I have classes like ⏎ ⏎ ```class Foo < SF::Transformable ⏎ include SF::Drawable ⏎ end``` ⏎ ⏎ How can I store in an array a type like `Array(SF::Transformable & SF::Drawable)` ? [https://gitter.im/crystal-lang/crystal?at=5c9927c39d9cc8114a1e1371]
<FromGitter> <alex-lairan> (I want to draw my entities)
<FromGitter> <girng> @oprypin
<oprypin> `¯\_(ツ)_/¯`
<oprypin> it's kind of a general question thankfully, the class and module themselves don't matter
<oprypin> now how to store an array of these things in a way that they still respond to both "interfaces"?
<oprypin> i dunno, maybe keep two arrays synchronized lol
knstn has left #crystal-lang [#crystal-lang]
<FromGitter> <TheOnlyArtz> How will I be able to convert a string to StaticArray(UInt8, 128) ?
<FromGitter> <Blacksmoke16> im pretty sure they have to be defined at compile time
<FromGitter> <TheOnlyArtz> What does that mean?
<FromGitter> <Blacksmoke16> meaning if you dont know what the string is at compile time i dont think you would be able to dynamically create a static array
<FromGitter> <TheOnlyArtz> I do know
<FromGitter> <TheOnlyArtz> Then how would I do that?
<FromGitter> <Blacksmoke16> you just want the bytes that make up a string?
<FromGitter> <TheOnlyArtz> I want to have a string and convert it to StaticArray(UInt, 128)`
<FromGitter> <alex-lairan> > maybe keep two arrays synchronized ⏎ ⏎ Why not, so I have to create a custom array class to hold both elements ^^
<FromGitter> <Blacksmoke16> is the string static? i.e. will it never change?
<FromGitter> <alex-lairan> ```code paste, see link``` ⏎ ⏎ This don't duplicate the `item`, it just duplicate reference to it ? [https://gitter.im/crystal-lang/crystal?at=5c9930ca8126720abc419429]
Liothen has quit [Quit: The Dogmatic Law of Shadowsong]
<FromGitter> <Blacksmoke16> @TheOnlyArtz https://play.crystal-lang.org/#/r/6kyb
<FromGitter> <Blacksmoke16> but if the string is static prob could just make it once, and see what the bytes are, then hardcode the static array of bytes vs doing that ?
<FromGitter> <TheOnlyArtz> What if the size of the string is unknown?
<FromGitter> <tenebrousedge> silly question: if my method is using `*` to collect an arbitrary number of arguments, is there any way for that to use an `Array` rather than a `Tuple`, or do I just use a `to_a` for that?
<FromGitter> <Blacksmoke16> then afaik you wouldnt be able to make a static array out of it
<FromGitter> <Blacksmoke16> prob easiest to just do like `"my dynamic string".bytes`
<FromGitter> <Blacksmoke16> `to_a` yea afaik
<FromGitter> <TheOnlyArtz> But I have to use UInt8 and a StaticArray
<FromGitter> <TheOnlyArtz> Are you sure I won't be able to ?
<FromGitter> <Blacksmoke16> not 100%, maybe someone else has an idea, but id vote no?
<FromGitter> <TheOnlyArtz> I need to pass `unsigned char`
<FromGitter> <TheOnlyArtz> And it has to be a StaticArray of UInt8
<FromGitter> <TheOnlyArtz> Maybe you have a workaround?
<FromGitter> <TheOnlyArtz> What if we use pointers in our C code?
<FromGitter> <TheOnlyArtz> Will they be Arrays and not StaticArrays?
<FromGitter> <Blacksmoke16> :shrug: afaik staticarray's size has to be known at compile time, you cant just dynamically create one
<FromGitter> <TheOnlyArtz> Is there an option to fill out the rest of the remaining bytes with `0_u8`?
<FromGitter> <TheOnlyArtz> I need the StaticArray's length to be 128 bytes so let's say I have a string of `8` bytes, can I feel the remaining 120 bytes with zeros?
<FromGitter> <Blacksmoke16> prob?
<FromGitter> <TheOnlyArtz> hm? how would it go?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6kyo
<FromGitter> <Blacksmoke16> hows that?
<FromGitter> <Blacksmoke16> so then yea in that case you could replace `string` with a var of the string you want
<FromGitter> <Blacksmoke16> prob some validation to make sure its not oversized wouldnt be bad either
<FromGitter> <TheOnlyArtz> Alright thank you
<FromGitter> <TheOnlyArtz> `Unhandled exception in spawn: Index out of bounds (IndexError) ⏎ `
<FromGitter> <Blacksmoke16> string is too big :P
<FromGitter> <Blacksmoke16> is what i would vote
<FromGitter> <TheOnlyArtz> uh no
<FromGitter> <TheOnlyArtz> It's just me not validating using `byte_at?()`
<FromGitter> <Blacksmoke16> ah fair enough
<FromGitter> <Blacksmoke16> this would truncate too big strings that dont fit in 128 bytes as well
<FromGitter> <TheOnlyArtz> Well yea
<FromGitter> <TheOnlyArtz> But the code is: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9936a081b15c5e4b86a57f]
<FromGitter> <Blacksmoke16> ok
<FromGitter> <z64> you can just copy the strings data to the sa ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c9938e70d7190505764e617]
<FromGitter> <TheOnlyArtz> oo
Liothen has joined #crystal-lang
<FromGitter> <Blacksmoke16> neat
<FromGitter> <TheOnlyArtz> Yep
<FromGitter> <Blacksmoke16> well there you go :P
<FromGitter> <TheOnlyArtz> How would I be able to take a FIle and make it into a buffer? using `IO.read_bytes(UInt8)` for example?
<FromGitter> <j8r> @tenebrousedge That's a `Tuple` because arguments are immutable. You can allocate an array with `to_a` indees
<FromGitter> <z64> what do you mean by "a buffer"? you just want to read the file into memory?
<FromGitter> <TheOnlyArtz> I'm trying to send a file over TCP
<FromGitter> <z64> is that a yes or a no
<FromGitter> <TheOnlyArtz> Idk
<FromGitter> <TheOnlyArtz> What requires to send a file over TCP?
<FromGitter> <j8r> Opening a File yields to an IO
<FromGitter> <j8r> Then you can read an arbitrary number of bytes
<FromGitter> <TheOnlyArtz> Ok, what requires to send a file over TCP using Crystal?
<FromGitter> <TheOnlyArtz> Well, using `read_bytes`?
<FromGitter> <j8r> For example
<FromGitter> <j8r> Or just `#read(slice)`
<FromGitter> <TheOnlyArtz> But I don't know the file's length
<FromGitter> <z64> if thats all you want to do, ⏎ ⏎ ```File.open("foo") do |file| ⏎ IO.copy(file, socket) ⏎ end``` ⏎ ⏎ will probably be fine [https://gitter.im/crystal-lang/crystal?at=5c993ced0d71905057650430]
<FromGitter> <TheOnlyArtz> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c993cee5547f77448653480]
<FromGitter> <TheOnlyArtz> I guess that worked
<FromGitter> <TheOnlyArtz> I need to take these bytes and construct a struct using them
<FromGitter> <TheOnlyArtz> So I will probably don't need to send it *directly*
<FromGitter> <z64> IO has an abstract API for reading an writing structs using `#read_bytes(T, endian)` and `#write_bytes(t, endian)` ⏎ this delegates to `T.from_io(io, endian)` and `T#to_to(io, endian)` respectively
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Was able to get around both using `responds_to?` instead [https://gitter.im/crystal-lang/crystal?at=5c995c65f3dbbd230cb896aa]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c995ca3d0133e21e515991f]
<FromGitter> <Blacksmoke16> bit cleaner
<FromGitter> <Maroo-b> is this an issue? ⏎ ⏎ ```slice = Slice["abc", "a"] ⏎ ⏎ slice.clone``` ⏎ ⏎ it raises: ```in src/slice.cr:125: Can only use primitive integers and floats with Slice.new(size), not String``` [https://gitter.im/crystal-lang/crystal?at=5c995cb65547f77448660fa1]
<FromGitter> <Blacksmoke16> i dobut it
<FromGitter> <bew> I'd say no, only primitives are supported with a Slice[] constructor
<FromGitter> <Maroo-b> ```slice # Slice["abc", "a"] : Slice(String)``` ⏎ ⏎ then should the parser raise an error for the syntax? [https://gitter.im/crystal-lang/crystal?at=5c995d8a5547f7744866176c]
<FromGitter> <bew> which syntax exactly?
<FromGitter> <Maroo-b> sorry, I mean there is no issue with the assignment when using Slice[] constructor. (As you mentioned that only primitives are supported with this constructor)
<FromGitter> <bew> no, Slice[] is not a special syntax only for Slice, it's just a call, it can be anything (if it's supported by the macro, or the method if it's one)
<FromGitter> <Maroo-b> if I'm not mistaken, it uses `initialize` https://github.com/crystal-lang/crystal/blob/master/src/slice.cr#L67
<FromGitter> <Maroo-b> I was asking because I was implementing sort method for Slice as discussed in this issue (https://github.com/crystal-lang/crystal/issues/6498 ) ⏎ and I stumbled on this behavior.
<FromGitter> <bew> hum... I don't know where you got that error but https://carc.in/#/r/6l2o
<FromGitter> <bew> ah for clone
<FromGitter> <bew> (maybe)
<FromGitter> <Maroo-b> yes for `clone`
<FromGitter> <Maroo-b> ```slice = Slice["abc", "a"] ⏎ ⏎ slice.clone``` [https://gitter.im/crystal-lang/crystal?at=5c9960062fb6800d807f0147]
<FromGitter> <bew> y sorry, I'd say `Slice#clone` is broken for non primitive types, it's worth opening an issue about it I think
<FromGitter> <Maroo-b> for the moment, I'm using just primitives to make the specs green. But it would be good if someone who has more experience with the source could confirm if it's an issue.
<FromGitter> <Maroo-b> cool, thank you @bew I'll open an issue now.