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> docopt is not great
<oprypin> < author of https://github.com/docopt/docopt.nim here
<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> <Blacksmoke16> Wouldn't it make more sense for . from to be a class method
<FromGitter> <Blacksmoke16> or do you really even need it?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9vim
<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> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f94e2f96c8d484be2a7898c]
<FromGitter> <Blacksmoke16> is what it was
<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*
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <wyhaines> @Blacksmoke16 Yep. That works great. Super useful idiom there. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f94ea62a7e77a0ff16b48fb]
<FromGitter> <Blacksmoke16> 👍 nice
chachasmooth has quit [Ping timeout: 246 seconds]
chachasmooth has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
_whitelogger has joined #crystal-lang
early` has quit [Quit: Leaving]
early has joined #crystal-lang
chachasmooth has quit [Ping timeout: 260 seconds]
chachasmooth has joined #crystal-lang
sorcus has quit [Ping timeout: 240 seconds]
sorcus has joined #crystal-lang
zorp has joined #crystal-lang
<raz> TIL, for small strings `+` is actually faster than `String.build`
<raz> or... maybe i should not use literals
* raz facepalms
<FromGitter> <j8r> that's right, once I've done a benchmark, for 2/3 concatenations, it is faster
<FromGitter> <j8r> that's because it uses optimizations related to bytes
<FromGitter> <j8r> interpolation using `String.build`, it is the same case
<FromGitter> <j8r> `var = "b"; "a" + var` is faster than `"a#{var}"`
<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?)
<raz> errr...
<raz> wait, wot
repo1 is now known as repo
<FromGitter> <j8r> don't have this personally
<FromGitter> <j8r> ha, for me interpolation is even faster
<FromGitter> <j8r> I think interpolation is faster for small strings
<FromGitter> <j8r> *for bigger strings
<FromGitter> <j8r> and concat faster for smaller
<FromGitter> <j8r> https://carc.in/#/r/9vju
<FromGitter> <j8r> raz: I added option type casting
<raz> huzza \o/
<FromGitter> <j8r> one just have to set, either `default: 1234`, or `type: Int32`
<FromGitter> <j8r> for default, the type will be inferred here to Int32
<FromGitter> <j8r> however, not sure if it is fine, there is no mandatory options
<FromGitter> <j8r> I think it is better to use arguments for this purpose
<FromGitter> <j8r> raz you're m-o-e on GitHub?
<raz> si
<FromGitter> <j8r> ... lol, you told me "info" is bad, but in your CLI you use "desc" :°
<raz> desc is short for "short description" :p
<FromGitter> <j8r> and "info" for "short information" haha
<raz> yeh i think we're both wrong, it should be "label" :p
<raz> label = short, description = long
* FromGitter * Blacksmoke16 votes `summary`/`description`
<raz> i would treat it like a button. button-summary? :P
<FromGitter> <Blacksmoke16> wait, we're describing cli args right?
<FromGitter> <Blacksmoke16> why do you even need 2 descriptions?
<raz> short description (one-liner) to be shown on the help screen of the parent command
<raz> s/description/label/
<raz> long description in the help screen of the command itself
<raz> a bit like button / tooltip, if it was a GUI
<raz> i think 'label' is better than desc or info because it kinda suggests it should be short
<raz> but then again, everyone has their own interpretation i guess
<FromGitter> <Blacksmoke16> is there an example of these being used?
ua_ has quit [Ping timeout: 260 seconds]
<raz> i dunno, there's probably plenty examples for all of them
<FromGitter> <Blacksmoke16> bbiaf, reinstalling my OS
<FromGitter> <j8r> raz: exactly
<FromGitter> <j8r> @Blacksmoke16 the long description is usually below the Usage section, it can therefore be bigger than the one next to the command
<FromGitter> <j8r> of the root `--help`
Liothen has quit [Ping timeout: 272 seconds]
Liothen has joined #crystal-lang
<FromGitter> <j8r> love it, the "woman" mode to read man pages in emacs
<FromGitter> <j8r> for an example, a bit like `git`, even though it is in a man pager
ua_ has joined #crystal-lang
repo1 has joined #crystal-lang
repo1 has quit [Client Quit]
repo has quit [Ping timeout: 272 seconds]
f1reflyylmao is now known as f1refly
repo has joined #crystal-lang
<FromGitter> <marghidanu> Hello, is there a way to use YAML discriminator inside another class?
<FromGitter> <Blacksmoke16> bk, took a bit longer than i was expecting :S
<FromGitter> <Blacksmoke16> @marghidanu I would imagine? Got an example?
<FromGitter> <marghidanu> @Blacksmoke16 I sure do: https://github.com/crystal-lang/crystal/issues/9849
<FromGitter> <Blacksmoke16> ah yup, thats a bug
<FromGitter> <marghidanu> looks like it, tried looking for some references to it in the GitHub issues but I didn't find anything
<FromGitter> <Blacksmoke16> 👍 pro tip, throw a `cr` on the code snippets for highlighting
<FromGitter> <marghidanu> Thanks will do that
<FromGitter> <marghidanu> I didn't know the identifier for highlighting
<FromGitter> <marghidanu> fixed
<FromGitter> <Blacksmoke16> should work on the 2nd one too
<FromGitter> <Blacksmoke16> but 👍, makes it easier to read :p
<FromGitter> <marghidanu> that's more like shell output
<FromGitter> <marghidanu> let's see how it looks
<FromGitter> <marghidanu> :)
<FromGitter> <marghidanu> good enough
<FromGitter> <marghidanu> Anyway, hopefully, it will be fixed in the next version
<FromGitter> <Blacksmoke16> we shall see
f1refly has quit [Quit: bye fags]
f1refly has joined #crystal-lang
repo has quit [Ping timeout: 272 seconds]
repo has joined #crystal-lang
yukai has joined #crystal-lang