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
<oprypin> dscottboggs_gitlab, well there is
<FromGitter> <dscottboggs_gitlab> yes, I found it right after and deleted those messages on gitter
<FromGitter> <dscottboggs_gitlab> sorry, should've said something for the IRC
<FromGitter> <mwlang> @j8r good points. I actually kind of struggle with the idea if `initialize(@stream : String , ....)` followed by an empty method body. Just seems weird to me, so I tend to assign those ivars in the body rather than take the shortcut.
<FromGitter> <mwlang> hmmm...that prompts an idea...is it possible for the language to have a feature whereby properties defined and not defaulted/initialized leads to automatically inferring an initialize that takes those arguments in order?
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> is there any way to yield values from a macro other than like...defining local variables named after the block args and passing then pasting the block?
<FromGitter> <dscottboggs_gitlab> sorry, for IRC, I meant to say `and then pasting` not `and passing then pasting`
<oprypin> mwlang, u can do it with a macro. there's macro `record` https://crystal-lang.org/api/0.35.1/toplevel.html#record(name,*properties)-macro
<oprypin> dscottboggs_gitlab, no,.. not really. the composition is done by calling another macro. macro has no compile-time returns or yields
<FromGitter> <dscottboggs_gitlab> ok thanks
<oprypin> mwlang, or oh i see what you mean. probably still possible but hey the language will error out until you do that anyway. so thats nice. and certainly much nicer for readers of the code
<FromGitter> <mwlang> @oprypin That's why I was suggesting as a new language feature. Instead of errorring out until you've taken care of initializing every property, auto-infer the initialize signature needed to successfully instantiate.
<FromGitter> <mwlang> if you try to instantiate without all the necessary values, you'll clearly see it in the list of possible overloads.
<FromGitter> <dscottboggs_gitlab> idk maybe if it was only by named arguments or some special syntax, but that's not always something you want
<FromGitter> <alexherbo2> what is the recommended style for dot a start of lines?
<FromGitter> <Blacksmoke16> prob whatever the formatter does
<FromGitter> <alexherbo2> ```def foo(string) ⏎ string ⏎ .transform_1 ⏎ .transform_2``` [https://gitter.im/crystal-lang/crystal?at=5f41c17159ac794e02bd25ce]
<FromGitter> <alexherbo2> ```def foo(string) ⏎ string ⏎ .transform_1 ⏎ .transform_2``` [https://gitter.im/crystal-lang/crystal?at=5f41c18159ac794e02bd25d3]
<FromGitter> <Blacksmoke16> what does the formatter do?
<FromGitter> <alexherbo2> I don't have formatter
<FromGitter> <Blacksmoke16> `crystal tool format`
<FromGitter> <dscottboggs_gitlab> ugh the formatter gets on my nerves so hard about that. ⏎ ⏎ It should be ⏎ ⏎ ```foobar.foo ⏎ .bar ⏎ .baz``` [https://gitter.im/crystal-lang/crystal?at=5f41c1bf49a1df0a129e20bc]
<FromGitter> <Blacksmoke16> i dont like either of those :S
<FromGitter> <dscottboggs_gitlab> you could also do ⏎ ⏎ ```foobar ⏎ .foo ⏎ .bar ⏎ .baz``` [https://gitter.im/crystal-lang/crystal?at=5f41c1dad4f0f55ebbd4a89a]
<FromGitter> <Blacksmoke16> i ilke that better
<FromGitter> <dscottboggs_gitlab> yeah but if someone writes it like the first example, it should do the hanging indent IMO
<FromGitter> <alexherbo2> in js we see it without indent
<FromGitter> <dscottboggs_gitlab> I'm pretty sure ESLint does it with an indent
<FromGitter> <mwlang> If I set a getter to a base class, is it true that I *must* cast it to descendant classes if I wish to access getter properties of the descendants?
deavmi has quit [Ping timeout: 240 seconds]
alexherbo2 has quit [Ping timeout: 240 seconds]
deavmi has joined #crystal-lang
[gnubie] has joined #crystal-lang
[gnubie] has quit [Ping timeout: 240 seconds]
[gnubie] has joined #crystal-lang
[gnubie] has quit [Remote host closed the connection]
<FromGitter> <grkek> @Blacksmoke16 it is done mate
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <grkek> do u ever sleep?
<FromGitter> <grkek> approve this thx
<FromGitter> <Blacksmoke16> sometimes :P
<FromGitter> <grkek> not healthy
<FromGitter> <Blacksmoke16> naw i do, lately its been like 2am to 9am
<FromGitter> <Blacksmoke16> normally 10pm to 9am
<FromGitter> <grkek> I am stuck in a loop
<FromGitter> <grkek> where I go to sleep and wake up at the same time
<FromGitter> <grkek> every day
woodruffw has quit [Ping timeout: 258 seconds]
<FromGitter> <dscottboggs> That sounds like a circadian rhythm?
<FromGitter> <grkek> @dscottboggs is this your non gitlab one?
_whitelogger has joined #crystal-lang
woodruffw has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> idk I was on my phone, idk what that is. But I will figure that out and switch to it because it has the right profile picture
<FromGitter> <grkek> you are using the gitlab profile now
<FromGitter> <dscottboggs_gitlab> it's my github one
<FromGitter> <dscottboggs_gitlab> yes I'm back on the desktop now
<FromGitter> <dscottboggs_gitlab> almost never use gitlab from my phone because I don't like the mobile app
<FromGitter> <grkek> @dscottboggs_gitlab also yes it is circadian rhythm
<FromGitter> <dscottboggs_gitlab> why are you talking about your circadian rhythm like it's weird to have one though?
<FromGitter> <dscottboggs_gitlab> BRB switching accounts
<FromGitter> <grkek> I always wake up at 09:00 everyday cuz of muh TESTOSTERONE
<FromGitter> <dscottboggs> back
<FromGitter> <grkek> Hello
<FromGitter> <mixflame> so I released my crystal app guys
<FromGitter> <mixflame> (crystal backend)
<FromGitter> <mixflame> hopefully apple won't find another fault with my ap
<FromGitter> <mixflame> app
<FromGitter> <mixflame> I got serverless user protection features with no admin frontend
<FromGitter> <grkek> Thats really nice :)
<FromGitter> <grkek> Best of luck yo you
<FromGitter> <grkek> Btw what did you use to build the backend?
dostoyevsky has quit [Quit: leaving]
dostoyevsky has joined #crystal-lang
r0bby has quit [Read error: Connection reset by peer]
r0bby has joined #crystal-lang
zorp has joined #crystal-lang
alexherbo2 has joined #crystal-lang
dostoyevsky has quit [Quit: leaving]
dostoyevsky has joined #crystal-lang
<oprypin> is there a more efficient way to do `EnumType.values.size`
hightower2 has quit [Ping timeout: 258 seconds]
<FromGitter> <naqvis> how about monkey-patching? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f42507fdfaaed4ef50400f5]
<oprypin> thanks but no :s
<FromGitter> <naqvis> :P
<FromGitter> <naqvis> why is that?
<oprypin> just no monkey-patching ever
<FromGitter> <naqvis> ```pp {{Foo.constants.size}}```
<FromGitter> <naqvis> no monkey patching
<FromGitter> <naqvis> :D
<FromGitter> <HertzDevil> is it possible to refer to the top-level namespace in a macro
<FromGitter> <HertzDevil> or at least obtain all top-level constants
<FromGitter> <Blacksmoke16> Idt, there's an issue for that feature
_whitelogger has joined #crystal-lang
<oprypin> interesting. FLT_MAX is Float32::MAX but FLT_MIN is Float32::MIN_POSITIVE
<oprypin> good on Crystal for the naming
<FromGitter> <grkek> Wonderful isn't it?
<FromGitter> <mwlang> Is this a compiler bug?? https://carc.in/#/r/9kwc
<FromGitter> <Blacksmoke16> `==`?
<FromGitter> <Blacksmoke16> `if @high_price = -20.0`
<FromGitter> <mwlang> do-h
<FromGitter> <mwlang> well, lost an hour to that!
<FromGitter> <Blacksmoke16> :p
ua has quit [Read error: Connection reset by peer]
ua has joined #crystal-lang
<oprypin> hol up
<oprypin> why does IO::Memory never expose capacity in any way
<oprypin> i can get the buffer but not the size of the buffer
<oprypin> agh also not possible to change capacity
<FromGitter> <sardaukar> hey all
<oprypin> hi long time no see
<FromGitter> <sardaukar> 👋
<FromGitter> <sardaukar> I know Crystal doesn't have runtime dispatch, but it's theoretically possible, right? it would just be a call to a function that checks the global function table for a name and returns the addr to the function we want to dispatch, then jump to it?
<oprypin> sardaukar, what of course crystal has runtime dspatch
<FromGitter> <sardaukar> I can jump to a function by name at runtime?
<oprypin> just apparently not in the sense that you're saying
<FromGitter> <sardaukar> ie call a method
<FromGitter> <sardaukar> for example here in this code
<FromGitter> <sardaukar> value = ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f428ca089cf2d584b6f12f8]
<FromGitter> <sardaukar> to replace the case, I'd need a macro right?
<FromGitter> <sardaukar> I can't just `cpu.registers.send(register_to_test).get_bit(bit)`
<oprypin> sardaukar, right
<FromGitter> <sardaukar> right
<FromGitter> <sardaukar> my original question was it it *theoretically* possible?
<FromGitter> <sardaukar> the resulting Crystal binary has some sort of function table, right?
<FromGitter> <naqvis> I highly doubt that, afaik crystal doesn't support RTTI
<FromGitter> <naqvis> i would have thought of going via function pointers aka `Proc` instead
<FromGitter> <sardaukar> hmm ok
<FromGitter> <sardaukar> thanks!
<FromGitter> <naqvis> sure thing, but let's see if someone else has different view on this
<FromGitter> <sardaukar> my guess is it would take some LLVM work to not only find the function in the table, but also pack arguments to call it (along with the jump)
<oprypin> sardaukar, there's no work, you literally just make a macro that writes out that kind of code and you're done
<oprypin> the case *is* the way to go
<FromGitter> <sardaukar> yes, I was just stretching a theoretical
<FromGitter> <Blacksmoke16> could you not use overloading?
<FromGitter> <j8r> @sardaukar I made https://github.com/j8r/crystal-object-send, to demonstrate that we can have `Object#send` features in Crystal with compile-time safety
<FromGitter> <j8r> In you case, oprypin is right, you can use a macro similar to `{% for x in ary %}` to generate the `when` branches
<FromGitter> <shinzlet> Howdy :) Is there a reason Crystal won't splat a StaticArray? Splatting dynamic arrays in Crystal isn't possible because their size isn't known at compile time, but I can't think of any good reason the following isn't possible: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f429a62dfaaed4ef504c605]
<FromGitter> <Blacksmoke16> use a tuple instead?
<FromGitter> <shinzlet> I would, but I'm dealing with a library that gives me a StaticArray.
<oprypin> shinzlet, no i dont think theres a reason
<oprypin> well maybe there is. "the argument to splat must be a tuple, full stop"
<oprypin> no reason not to change the rule though
<FromGitter> <shinzlet> Do you think it would be worth me opening a feature request? From my searching on github issues, this doesn't seem to have been brought up before
<oprypin> seems ok
<FromGitter> <shinzlet> Thanks! I'm a newbie with working on other people's projects haha
postmodern has joined #crystal-lang
<FromGitter> <shinzlet> Also, nice to meet you @oprypin - I've been using crSFML for a while now! It's lovely stuff :)
<postmodern> what's the difference between uninitialized MyCStruct and MyCStruct.new? Does initializing a C struct ensure the memory is zeroed?
<FromGitter> <naqvis> @shinzlet ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f429d0648237809373a33da]
<oprypin> shinzlet, ^_^
<oprypin> postmodern, no it's random garbage. with modern cpu protections maybe it'll turn out to be zeroed in many cases, but not to be relied on
<postmodern> oprypin, good to know. I remember Solaris didn't zero the physical memory on bootup, where as Linux tends to zero memory.
<FromGitter> <naqvis> @oprypin no, you are wrong
<FromGitter> <naqvis> C Struct.new initializes,A C struct starts with all its fields set to "zero": integers and floats start at zero, pointers start with an address of zero, etc.
zorp has quit [Ping timeout: 258 seconds]
<FromGitter> <naqvis> and if you want to avoid the initialization then go with `uninitialized`
<oprypin> naqvis, ok but the question was about `uninitialized` , i guess i misread the details
<oprypin> postmodern, .new ensures zeroed, i think, yes
<oprypin> so that's the difference
<oprypin> hm nice, macros can seamlessly preserve blocks https://carc.in/#/r/9kxi
<FromGitter> <j8r> @naqvis too bad it takes only Array, and not any Indexable
<FromGitter> <j8r> There should be a more efficient way, using macros (`from` use them BTW)
<FromGitter> <Sija> any1 knows is there a way to add `@[JSON::Field]` annotation to already defined property?
<FromGitter> <Blacksmoke16> ```@[Json::Field(...)]` ⏎ @value : Int32``` ⏎ ⏎ ? [https://gitter.im/crystal-lang/crystal?at=5f42b138dfaaed4ef504fd12]
<FromGitter> <dscottboggs_gitlab> > Error: undefined method 'to_unsafe' for Proc(Pointer(UInt8), Pointer(UInt8), Pointer(Void), Nil) ⏎ ⏎ I'm confused...
<FromGitter> <dscottboggs_gitlab> how do you pass a callback to C if there's no `Proc#to_unsafe`?
<FromGitter> <dscottboggs_gitlab> > Error: undefined method 'to_unsafe' for Pointer(Void) ⏎ ⏎ WTF?
<FromGitter> <Blacksmoke16> i mean a pointer is already unsafe so that makes sense?
<FromGitter> <galvertez> is there any way to check if a socket has data before even trying to read from it?
<oprypin> in case you're actually calling .to_unsafe on either of these --- just don't
<FromGitter> <dscottboggs_gitlab> but I don't have `#to_unsafe` anywhere in my code
<FromGitter> <dscottboggs_gitlab> also there's this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f42b3b848237809373a6b74]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<oprypin> show code
<FromGitter> <dscottboggs_gitlab> gimme a minute I gotta create the repo and all
<postmodern> hmm noticed that the crystal compiler cannot inspect when you call another #initialize within an #initialize to set an @ivar. the compiler will think there's a possibility the @ivar can be Nil. If I replace the #initialize call with a literal @ivar = ... then it works.
<FromGitter> <dscottboggs_gitlab> nvm I already had a repo just had to commit and push: https://github.com/dscottboggs/webview.cr/blob/bfbb1967ed93230e39664c664b57cc49a00a8577/src/webview.cr#L122
<oprypin> postmodern, yes unfortunately. this basically reners calling initialize inside initialize almost useless
<FromGitter> <dscottboggs_gitlab> not exactly the prettiest code to look at lol
alexherbo2 has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> postmodern, yes, you must assign all ivars within one `#initialize` unfortunately. I usually use `self.new` if I need overloads of `.new`
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16 was actually hoping to get your thoughts on the API documented at the top of that page too, if you get a chance
<oprypin> postmodern, so `def initialize` can only initialize vars directly. meanwhile `def self.new` is free to call any other function. if your alternative way of constructing the object can wholly rely on another initialize, then you write as `def self.new`
<FromGitter> <dscottboggs_gitlab> > ` 5 | {% if flag?(:freebsd) %}` ⏎ > ` ^` ⏎ > `Warning: expanding macro` ⏎ ⏎ Um... [https://gitter.im/crystal-lang/crystal?at=5f42b6fcec534f584fb836fe]
<FromGitter> <dscottboggs_gitlab> (I'm on manjaro)
<FromGitter> <dscottboggs_gitlab> that's compiled from source at 0.35.1
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f42b7c489cf2d584b6f762b]
<oprypin> dscottboggs, why are u posting such tiny parts of the error
<FromGitter> <dscottboggs_gitlab> just don't want to flood the channel with huge blobs
<FromGitter> <dscottboggs_gitlab> nor use pastebin.com lol
<oprypin> well you'll have to
<oprypin> use https://bpa.st/ instead if that helps lol
<FromGitter> <dscottboggs_gitlab> with dark mode too -- not bad
<oprypin> dark mode that i wouldn't have to endure along with you :) (ghm ghm hastebin)
<FromGitter> <dscottboggs_gitlab> https://bpa.st/LOLQ
<oprypin> LOLQ
<FromGitter> <dscottboggs_gitlab> heh
<oprypin> O_o what is that `in(Location.local)`
<FromGitter> <dscottboggs_gitlab> it looks like a branch of the FreeBSD code that didn't get updated to be cool with the new `in` keyword
<oprypin> oh..
<FromGitter> <dscottboggs_gitlab> but like, why is `freebsd` defined at all?? this is linux
<FromGitter> <dscottboggs_gitlab> but that's just the one I compiled, probably not important
<FromGitter> <dscottboggs_gitlab> the other one is what I'm trying to figure out
<oprypin> i'm lost
<FromGitter> <dscottboggs_gitlab> in what I'm saying or the error?
<FromGitter> <dscottboggs_gitlab> ah I got the traceback
<FromGitter> <dscottboggs_gitlab> https://bpa.st/U6HQ
<FromGitter> <dscottboggs_gitlab> ayyup that's a bug
<FromGitter> <dscottboggs_gitlab> and of course it's in the ugliest shit looking macro laden code
* FromGitter * dscottboggs_gitlab rolls eyes
<oprypin> gotta unroll ... the macro
<oprypin> like, it's your own macro, right?
<oprypin> paste the contents, even with {%debug %}, get it back into a simple state and see if that clears things up
<FromGitter> <dscottboggs_gitlab> Yeah, I'm trying to reduce it now. i got all the macro shit out of there and the bug's still showing up, gimme a sec
<FromGitter> <naqvis> > @naqvis too bad it takes only Array, and not any Indexable ⏎ ⏎ yeah and tbh I don't think this `from` makes any sense when someone still need to annotate things, as compiler should be able to infer that from passed array arg
<FromGitter> <naqvis> also it seems strange on why someone would require to convert array to tuple?
<FromGitter> <naqvis> might be i'm not able to foresee any use-case :P
<FromGitter> <naqvis> @j8r 👆
<FromGitter> <dscottboggs_gitlab> oprypin, the compiler exception goes away when I remove these lines https://github.com/dscottboggs/webview.cr/blob/2cb46c12e5c846025a7f3b3094ad554eb0f0141f/src/webview%20copy.cr#L30-L32 ⏎ ⏎ When I do that, so that it looks like this (https://github.com/dscottboggs/webview.cr/blob/fc2387519e6e5e45686adf4692078e26faf6c6ab/src/webview%20copy.cr), it still doesn't compile, and instead I get this
<FromGitter> ... message https://bpa.st/UQXQ
<FromGitter> <j8r> There are cases @naqvis , pattern matching in case/when, etc
<FromGitter> <naqvis> got an example? array -> tuple usage in pattern matching?
<oprypin> dscottboggs, i still fear that it's that ,\n breaking things
<FromGitter> <dscottboggs> Where?
<oprypin> ` %callback.pointer,`
<FromGitter> <dscottboggs> trying it without
<FromGitter> <dscottboggs> nope, still a problem
<oprypin> dang
<FromGitter> <dscottboggs> I think it's `Proc#pointer` calling `#[]` on `@internal_representation`, but some method in that getting inlined, but something goes wrong with that...then when there's an error, it throws an exception while trying to print the traceback.
<FromGitter> <dscottboggs> but I still 1. can't reduce it further than the examples I posted, and 2. don't get why all this is happening at compile-time
<FromGitter> <dscottboggs> I added ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ So I need to make my proc return `Pointer(Void).null` instead of nil [https://gitter.im/crystal-lang/crystal?at=5f42c5be9bad075eacd0e6f6]
<FromGitter> <dscottboggs> fucks sake
<oprypin> lol
<FromGitter> <dscottboggs> ...and it compiled!
<oprypin> congrats 🎉
woodruffw has quit [Ping timeout: 240 seconds]
<FromGitter> <wyhaines> @galvertez If you are asking if there is an IO#select type method, there is not. ⏎ ⏎ You can do non-blocking read operations, and you can do things like put a blocking read inside of a fiber, with the data read going to a channel, and do a select on the channel(s) in order to act when one of them has something. ⏎ ⏎ i.e. the typical C pattern, which Ruby inherited, of utilizing an IO select type
<FromGitter> ... operation (or epoll, or kqueue) isn't directly available, but there are other options which still work well. ... [https://gitter.im/crystal-lang/crystal?at=5f42d5325580fa092b1ba9d5]
woodruffw has joined #crystal-lang
woodruffw has quit [Ping timeout: 240 seconds]
woodruffw has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo2 has joined #crystal-lang
<FromGitter> <j8r> That's particularly useful for games :)
<FromGitter> <j8r> It be easily event-driven
HumanGeek has joined #crystal-lang
zorp has joined #crystal-lang
Human_G33k has quit [Ping timeout: 258 seconds]
<FromGitter> <sardaukar> @j8r thanks for the link for object-send, will have a look!
alexherbo24 has joined #crystal-lang
<FromGitter> <j8r> keep it mind it is likely to be better to make your own one ;)
<FromGitter> <Blacksmoke16> or ideally refactor things to not need that
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo24 is now known as alexherbo2
<FromGitter> <shinzlet> https://github.com/crystal-lang/crystal/blob/41bd18fbea4aec50aad33aa3beb7a0bf30544186/src/static_array.cr#L32 (In the documentation for `StaticArray(T, N)`), it says that "The generic argument type `N` is a special case in the type grammar as it doesn't specify a type but a size. Its value can be an `Int32` literal or constant." Does anyone know where that "special case" is implemented?