ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.36.0 | Fund Crystal's development: | GH: | Docs: | Gitter:
<FromGitter> <> The playground uses websockets?
<FromGitter> <> Ho yes...
<FromGitter> <> The playground being in the compiler does not make things easy...
<FromGitter> <> is it commonly accepted that applications should commit shard.lock, while libraries shouldn't?
<FromGitter> <Blacksmoke16> pretty much yea
<FromGitter> <> Because a library is not used directly
<FromGitter> <> nice thx
<FromGitter> <> Locking versions allows to reproduce a build – by the way as you knoe not that true because nothing stops to modify tags
<FromGitter> <> I could be possible to even not have SHA1, but it will be insecure...
<FromGitter> <> Which could be fine actually, if only used locally
<FromGitter> <> 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> <> @Blacksmoke16: just `collection : Enumerable` won't do?
<FromGitter> <Blacksmoke16> ```code paste, see link``` []
<FromGitter> <Blacksmoke16> nop
<FromGitter> <Blacksmoke16> namedtuple isnt an enumerable
<FromGitter> <> Right. Why giving this then?
<FromGitter> <Blacksmoke16> just so happened is what i tested with first
<FromGitter> <> 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? (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? (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, 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 {{}} 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: ... 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:
<hightower2> well got it working with:
<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 -]
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> <> 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> <> Maybe there is an optimization with the hash literal with the initial capacity?
<FromGitter> <> j8r ( @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> <> 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> <> @hightower2 j8r ( , yes, they are the same after all
<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> <> 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> <> 🎉 really proud of it - and no javascript required!
<FromGitter> <Blacksmoke16> neat
<hightower2> awesome idea
<FromGitter> <> 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> 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:
<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> <> 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,
<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,
<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