ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.36.0 | 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
<FromGitter> <jrei:matrix.org> The playground uses websockets?
<FromGitter> <jrei:matrix.org> Ho yes...
<FromGitter> <jrei:matrix.org> The playground being in the compiler does not make things easy...
<FromGitter> <oprypin:matrix.org> is it commonly accepted that applications should commit shard.lock, while libraries shouldn't?
<FromGitter> <Blacksmoke16> pretty much yea
<FromGitter> <jrei:matrix.org> Because a library is not used directly
<FromGitter> <oprypin:matrix.org> nice thx
<FromGitter> <jrei:matrix.org> Locking versions allows to reproduce a build – by the way as you knoe not that true because nothing stops to modify tags
<FromGitter> <jrei:matrix.org> I could be possible to even not have SHA1, but it will be insecure...
<FromGitter> <jrei:matrix.org> Which could be fine actually, if only used locally
<FromGitter> <oprypin:matrix.org> yes i know that sucky part about it
<FromGitter> <Blacksmoke16> is there a way to type restrict an argument to a key/value enumerable?
<FromGitter> <Blacksmoke16> maybe `def test(collection : Enumerable({K, V})) forall K, V` would work?
<FromGitter> <Blacksmoke16> naw
richbridger has joined #crystal-lang
teardown has quit [Remote host closed the connection]
teardown has joined #crystal-lang
<FromGitter> <Blacksmoke16> guess ill just not type it and let the compiler handle it
<FromGitter> <Blacksmoke16> `Error: undefined method 'join' for NamedTuple(foo: String, key: Bool)` rip
hightower2 has joined #crystal-lang
<hightower2> Ehm how can I iterate over enum members from a macro?
<FromGitter> <Blacksmoke16> `@type.constants`
<hightower2> exceptional, thanks!
<FromGitter> <jrei:matrix.org> @Blacksmoke16: just `collection : Enumerable` won't do?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=601607f00eed905f18805d71]
<FromGitter> <Blacksmoke16> nop
<FromGitter> <Blacksmoke16> namedtuple isnt an enumerable
<FromGitter> <jrei:matrix.org> Right. Why giving this then?
<FromGitter> <Blacksmoke16> just so happened is what i tested with first
<FromGitter> <jrei:matrix.org> Or maybe Enumerable | NamedTuple haha
<FromGitter> <Blacksmoke16> i just made it `Hash`, as apparently named tuple doesnt support `join` anyway so im just passing the `**params` to other overload via `params.to_h` :shrug:
<FromGitter> <Blacksmoke16> worst case you just need to `**nt`
<FromGitter> <Blacksmoke16> or call `.to_h` on it
<hightower2> hm why doesn't this work? https://carc.in/#/r/ac49 (could be obvious, but I'm tired yet trying to finish something up)
<FromGitter> <Blacksmoke16> wrap em in `{% begin %}`/`{% end %}`
<hightower2> worked, danke schoen
<FromGitter> <Blacksmoke16> 👍
<hightower2> Ah one more, what am I doing wrong here? https://carc.in/#/r/ac4b (Tried to explain my purpose below the macro)
<hightower2> ah parens () for one at least, so that it treats it as a hash instead of block
<FromGitter> <Blacksmoke16> yea, thats what i was going to say
<hightower2> m indeed, that was the only issue. ok awesome
<hightower2> (and that m.resolve had to be m.id, that was just mispaste in the carc example)
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<hightower2> one thing remains in that paste... when I do {% for m in Tput::Key.constants %} EventHandler.event {{m.id}} that basically changes what 'm' is... so instead of a hash with ( Tput::Key => Event ), I end up with a hash of ( Event => Event )
<hightower2> or hm, not sure if that's accurate description
<hightower2> how can I ask a class to give me its constant? Like {% ha[ Tput::Key[m] ] = m %}
<hightower2> Have this so far: https://carc.in/#/r/ac4c ... but Tput::Key.constant(m) gets me the enum value back (Int32) rather than enum member itself
<FromGitter> <Blacksmoke16> not sure i follow what the goal is there
<hightower2> Here's the purpose explained: https://carc.in/#/r/ac4d
<hightower2> well got it working with: https://carc.in/#/r/ac4f
<hightower2> But I wanted to avoid assigning in runtime the elements one by one
<FromGitter> <Blacksmoke16> wouldnt it be easier to do that as a method on the enum?
<hightower2> it would, but I can't do this as a built-in feature of Tput::Key, must do it in/from the project that uses it as a dependency
<hightower2> so not sure how I'd do that
<FromGitter> <Blacksmoke16> ok
<hightower2> I guess the only final improvement to what I have in that last paste would be if I could somehow generate the complete hash and assign it at once, instead of basically using macros to generate hash assignments in a key-by-key fashion
<hightower2> (and in runtime)
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 260 seconds]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
postmodern has quit [Quit: Leaving]
pyra has quit [Ping timeout: 272 seconds]
_ht has joined #crystal-lang
deavmi has quit [Ping timeout: 272 seconds]
<FromGitter> <oprypin:matrix.org> hightower2, heh dont feel too bad about that, a hash literal has no difference from creating an empty hash and adding items one by one at runtime
<hightower2> great, useful to know, thanks
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 265 seconds]
deavmi has joined #crystal-lang
<FromGitter> <jrei:matrix.org> Maybe there is an optimization with the hash literal with the initial capacity?
<FromGitter> <oprypin:matrix.org> j8r (https://matrix.to/#/@jrei:matrix.org): @hightower2 i just looked at the difference in llvm ir generated by the two cases, and they're definitely different enough that i seriously doubt my claim now
<FromGitter> <oprypin:matrix.org> no hold on, i made a mistake in the comparison
<hightower2> Right, yeah re. capacity I already added the default amount since I know how many elements there will be. But I thought there were other differences too.
<hightower2> Hm is there a way to ask how many members an enum has?
<hightower2> seems silly to call #names.size or the like...
<FromGitter> <Blacksmoke16> `@type.constants.size`?
<hightower2> undefined method #constants
<FromGitter> <Blacksmoke16> its a macro method
<hightower2> (doing it outside of macros... in regular code)
<hightower2> but I guess I could use a macro, yes
<hightower2> yeah done so, thanks for the idea
<FromGitter> <oprypin:matrix.org> @hightower2 j8r (https://matrix.to/#/@jrei:matrix.org) , yes, they are the same after all https://gist.github.com/262dcd1ac32c8ca91557e0665c8f3f5d
<hightower2> thank you kindly for confirming++
<hightower2> What's my best bet to install a timeout on IO#read_char ? Do I really resort to setting io.read_timeout= even though I only sometimes need to read with a timeout?
<hightower2> (and other/most times without a timeout)
<hightower2> ok done so for now, setting and resetting io.read_timeout before/after reading if a read with timeout is to happen
<yxhuvud> How cute. Now my test suite ends in a BUG 50% of the time and passes the rest.
<FromGitter> <oprypin:matrix.org> yxhuvud, nondeterministic compile error? ;o
<yxhuvud> nah, it is the event loop that somehow wakes a fiber it shouldn't. Which is a very fair error considering I'm monkeypatching half the event loop. just a bit irritating to get it only sometimes.
DTZUZU_ has joined #crystal-lang
DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU_ has quit [Ping timeout: 240 seconds]
<FromGitter> <oprypin:matrix.org> https://oprypin.github.io/install-crystal/configurator.html 🎉 really proud of it - and no javascript required!
<FromGitter> <Blacksmoke16> neat
<hightower2> awesome idea
<FromGitter> <oprypin:matrix.org> wait until you view the page's source code 😂
<FromGitter> <RespiteSage> That's super cool, @oprypin.
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/blob/33c97d419c88b4c6595786597f0ed04c7973b283/src/http/server/response.cr#L227 why does the `HTTP::Server` always write `content-length`?
<FromGitter> <Blacksmoke16> afaik thats breaking RFC when the response status is 304
hightower2 has quit [Ping timeout: 246 seconds]
hightower2 has joined #crystal-lang
hightower2 has quit [Ping timeout: 264 seconds]
hightower2 has joined #crystal-lang
_ht has quit [Remote host closed the connection]
<FromGitter> <gunn> @Blacksmoke16 Hey, thanks for helping me with my server stuff a couple of days ago - the problem was what you suggested - chrome blocking parallel loads, when I test with curl it works perfectly.
<raz> blacksmoke is right: https://tools.ietf.org/html/rfc7230#page-30:~:text=3.3.2.%20%20Content%2DLength
<raz> looks like there are a bunch more cases where content-length needs special care
<FromGitter> <Blacksmoke16> @gunn nice! good to hear
postmodern has joined #crystal-lang
<postmodern> does crystal support something like Class#prepend which puts the module above the Class in the ancestory hiearchy, allowing it to intercept method calls and then call super().
<FromGitter> <Blacksmoke16> im pretty sure if you redefine a method from a module in a class and call `super` it'll invoke the module's implementation
<FromGitter> <jrei:matrix.org> you can't manipulate the program structure at runtime
<postmodern> Blacksmoke16, prepend works differently. it let's you define a method from the class, but in the module, and calling super will call the class'es method
<hightower2> I seem to remember asking this question years ago (since I wanted it like it works in Ruby) and was told it doesn't exist.
<FromGitter> <Blacksmoke16> yea idt thats a thing
<FromGitter> <Blacksmoke16> got an example of how it would work?
<FromGitter> <Blacksmoke16> like is it just allowing you to call the modules implementation before the classes? or?
<hightower2> Just instead of `include` which adds it to the end/most recent in the list, this one adds it at the start/most far away
<hightower2> basically it's an unshift into the list of parents
<FromGitter> <Blacksmoke16> ofc if a module defines a method and the class doesnt override it, the module is what'll be called. If the class overrides it, it can call `super` to use the modules implementation first
<FromGitter> <Blacksmoke16> i see
<postmodern> Blacksmoke16, https://carc.in/#/r/ac9l
<postmodern> Blacksmoke16, also you can do `super if defined?(super)` in case the class doesn't define the method, although `defined?` always struck me as a bit too magical.
<FromGitter> <Blacksmoke16> you can get kinda close, https://play.crystal-lang.org/#/r/ac9p
<postmodern> also lets you do things like wrap around super and catch exceptions, modify input arguments, modify return values, all without the class'es method realizing it
<hightower2> ah yes, my description was off
deavmi has quit [Ping timeout: 265 seconds]
deavmi has joined #crystal-lang
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang