<oprypin>
writing a parser which generates crystal code in a `macro run` would be quite nice
<oprypin>
i think translating this Nim version of it to Crystal would actually be the most direct one
<FromGitter>
<Blacksmoke16> I just like having a somewhat standardized format/structure to reference
<FromGitter>
<Blacksmoke16> Didn't realize it was actually a way to define the parser
zorp has quit [Ping timeout: 240 seconds]
deavmi has quit [Ping timeout: 272 seconds]
deavmi has joined #crystal-lang
<FromGitter>
<wyhaines> If I have a Hash of some type.... say `Hash(String, Int32)`, is there a way to dynamically create a new hash with the same type signature?
<FromGitter>
<Blacksmoke16> hash.class.new?
<FromGitter>
<wyhaines> Doh! *sigh*
<FromGitter>
<Blacksmoke16> :p
<FromGitter>
<wyhaines> Hmmm. The real question, then. :) ⏎ ⏎ I have a class, SplayTreeMap. It implements pretty much a complete Hash method signature. It also implements a `#from` method that can be passed anything that implements `#each`, and it'll iterate that object and use it to populate the tree. ⏎ ⏎ ```stm = SplayTreeMap(String, Int32).new.from({"a" => 1, "b" => 2})``` ... [
<FromGitter>
<wyhaines> The only way that works is if I can extract a type signature, and then dynamically use that to create a new SplayTreeMap, which is basically what I am trying to figure out how to do. ⏎ ⏎ And if I can do that, then `from` can be both a class and an instance method, as what it really does is to add the elements to the structure (i.e. it doesn't just replace the values with whatever is in the object passed
<FromGitter>
... into `from`).
<FromGitter>
<Blacksmoke16> can you make a playground link example?
<FromGitter>
<wyhaines> Right now, playground isn't even loading your link. Still waiting on it.
<FromGitter>
<mwlang> If a websocket goes silent (not closed, but server no longer sending data), is there a way to notice that so I can restart the websocket?
<FromGitter>
<mwlang> what I mean is a timeout or something along those lines where no callbacks on the websocket is fired for a certain period of time, and I can send a "timeout" message on the channel I'm using to send messages so the program can do something about it (in this case, I want to gracefully teardown and reconnect to the server.
<FromGitter>
<wyhaines> @Blacksmoke16 Ah. That idiom is exactly what I think I was missing in my brain. *goes to try it*
<raz>
hm yup, it's true even for dynamic strings (although the difference is much smaller there, String.build prob gains an advantage with larger strings)
<raz>
and yep, makes sense that interpolation is slower (as it has to parse the string first - although perhaps that part could be cached?)