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