<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> 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>
<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>
<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> 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> 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> 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>
<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.
<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>
<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
<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>
<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>
<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>
<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> 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>
<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.