ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.22.0 | Fund Crystal's development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
<Papierkorb> Hashes, Arrays, etc., are all supported and just work
<Papierkorb> You also usually map data, not code. obviously, mapping a block (or proc for that matter) can't work.
<FromGitter> <jwoertink> Is there a way with JSON mapping to specify the value comes from a method?
<FromGitter> <jwoertink> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=593c8fbd6462d8493cfdb0af]
<FromGitter> <jwoertink> or is my only option here to create a `@title` ?
<FromGitter> <jwoertink> and define that in initialize
<FromGitter> <akzhan> another one to create alternative to json.mapping. it’s just a macro
<FromGitter> <l3kn> y
<FromGitter> <codenoid> sir, how to `explored(delimiter, string) ` (php version) in crystal
<FromGitter> <codenoid> & how to do ` json_encode() ` and ` json_decode() ` in crystal, thanks
rohitpaulk has joined #crystal-lang
hightower2 has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 240 seconds]
splitty_ has quit [Read error: Connection reset by peer]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <elorest> @codenoid https://crystal-lang.org/api/0.22.0/JSON.html
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <elorest> If you have a hash you can just call `hsh.to_json`. If you have as string you can call `JSON.parse(json_string)`
<FromGitter> <bararchy> WOW !!
<FromGitter> <bararchy> מןבק !
<FromGitter> <bararchy> @elorest Very nice :)
<FromGitter> <bararchy> Did someone implamented BagOfWords or Word2Vec ?
<FromGitter> <codenoid> thanks, but how to do explode()
hightower2 has joined #crystal-lang
_whitelogger has joined #crystal-lang
<hightower2> I'm trying to bench x.is_a?(Class) vs. making sure that all possible types support the same method, so that I simply call x.method(): https://pastebin.ca/3831550
<hightower2> However the results are about 340M/s for both. Looks like my code is being optimized and I don't see the actual test results, or?
<oprypin> ‎hightower2‎, is_a? is not an actual method, it may be resolved at compile time
<oprypin> x = 5==5 ? BX.new : "blah"
<oprypin> try that one
<hightower2> Hmm, same results
<FromGitter> <bew> @codenoid for explode, it's `"some string".split(' ')` and it gives `["some", "string"]`
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
A124 has quit [Read error: No route to host]
A124 has joined #crystal-lang
<FromGitter> <sdogruyol> hey all
<FromGitter> <bararchy> Sup @sdogruyol
<FromGitter> <sdogruyol> hey @bararchy, doing great! How about you
<FromGitter> <bararchy> All good, trying to figure out how much ML libs I need to create in order to make Crystal a viable canidate for ML development ^^
<FromGitter> <sdogruyol> that sounds interesting :P
<FromGitter> <bararchy> Well, I would Love some help but it seems every repo I find that uses ML algorithems or technologies is unmaintained or unresponsive
<FromGitter> <bararchy> :(
<FromGitter> <sdogruyol> yeah, we need to keep people
<hightower2> I have a basic problem: I call something like "@x.close if @x && !@x.closed?" , where @x : IO | Nil. However, this is Right, and same for the def one() 1 endgiving me: undefined method 'closed?' for Nil (compile-time type is (IO | Nil))
<hightower2> What is the correct solution for this basic problem?
<hightower2> Crap, sorry, let me try again:
<FromGitter> <bararchy> the big issue is that you use @x instead of x
<hightower2> I have a basic problem: I call something like "@x.close if @x && !@x.closed?" , where @x : IO | Nil. However, this is giving me: undefined method 'closed?' for Nil (compile-time type is (IO | Nil))
<FromGitter> <bararchy> because @x can change mid test
<hightower2> You mean I need to do x = @x and do things on x then, or?
<FromGitter> <bararchy> so @x can be non nil when the if check is done, but, change to nil when .close is called
<FromGitter> <bararchy> yeha
<FromGitter> <felipeelias> @hightower2 coincidence, I just ran into the same issue right now :D
<FromGitter> <bararchy> so there can be only one path of execution
<hightower2> felipe: hehe :)
<hightower2> bararchy: maybe you have a valid point, but it is not my problem here. My problem is that @x is defined as being IO | Nil.
<hightower2> And so I can't call @x.close because @x can be nil.
<hightower2> And I of course can't initialize @x up front with anything useful, so I must allow it to be nil
<FromGitter> <bararchy> I know, but, when you do ⏎ x.close if x.is_a?(IO)
<FromGitter> <bararchy> it will work only if x is not @x
<hightower2> bararchy: wonderful, thanks, that fixed it
<FromGitter> <bararchy> :) No worries
<FromGitter> <felipeelias> my problem is a bit different, I'm trying to raise someting if a variable is nil or it's size is < 5
<FromGitter> <felipeelias> raise "uri_host_required" if uri.host.nil? || uri.host.size < 5
<FromGitter> <felipeelias> and i get the same "undefined method 'size' for Nil (compile-time type is (String | Nil))"
<hightower2> Maybe our man bararchy can help again :)
<FromGitter> <bararchy> XD
<FromGitter> <sdogruyol> @felipeelias url.not_nil!
<FromGitter> <bararchy> @sdogruyol yeha !, this is a good answer
<FromGitter> <sdogruyol> sometimes you need explicity tell the compiler that it can't be nil
<FromGitter> <bararchy> because you only need it not to be nil, not a specific thing
<FromGitter> <felipeelias> something like this? if uri.host.nil? || uri.host.not_nil!.size < 5
<FromGitter> <felipeelias> it feels weird for me, that's why i'm asking :)
<FromGitter> <sdogruyol> yeah it feels weird
<FromGitter> <sdogruyol> why don't you wrap it in
<FromGitter> <sdogruyol> ```if uri.host ⏎ # Do stuff ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=593d257b6549436c7d383b36]
<FromGitter> <bararchy> you can even ⏎ ⏎ ```if uri.host.is_a?(String) ⏎ ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=593d25a9142826e972a40ea1]
<FromGitter> <bararchy> to avoid other types leaking in
<FromGitter> <bararchy> if that might happen
<FromGitter> <bararchy> if not, then @sdogruyol example is much nicer
<FromGitter> <felipeelias> @bararchy @sdogruyol i might go with splitting this into two separated branches... to give more context, i'm creating a very specific URI validator
<FromGitter> <felipeelias> class UriValidator ⏎ def self.call(value : String) ⏎ ⏎ ```code paste, see link``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=593d2637142826e972a41109]
<FromGitter> <felipeelias> damn, how do i paste code?
<FromGitter> <sdogruyol> use ```
<FromGitter> <felipeelias> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=593d2653142826e972a41168]
<FromGitter> <felipeelias> geez, sorry
<FromGitter> <sdogruyol> ``````
<FromGitter> <bew> (put a new line after ```)
<FromGitter> <felipeelias> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=593d267102c480e67232544b]
<FromGitter> <bararchy> Better :)
<FromGitter> <felipeelias> hell yeah :)
<FromGitter> <bew> hu no nvm
<FromGitter> <felipeelias> @bew a new line after the ``` was missing
<FromGitter> <bararchy> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=593d26e702c480e67232558f]
<FromGitter> <bararchy> maybe this ? nil becomes an empty string if called on by .to_s
<FromGitter> <felipeelias> @bararchy hmmm, that makes more sense
<FromGitter> <felipeelias> yeah, i'm going to go with that, thanks @bararchy, @sdogruyol
<FromGitter> <bararchy> Or, just do something like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=593d2773142826e972a41552]
<FromGitter> <bew> I was thinking the same
<FromGitter> <sdogruyol> yeah safer
<FromGitter> <bew> (but using `raise "..." unless host`)
<FromGitter> <felipeelias> why is it safer?
Raimondi has quit [Read error: Connection reset by peer]
<FromGitter> <bararchy> but, if you call this thing very fast and multiple times maybe the allocation might be a performance issue ?
<FromGitter> <bew> @bararchy where is the alocation?
Raimondi has joined #crystal-lang
<FromGitter> <bararchy> @felipeelias because uri.host is cannling the host method\class veriable of uri which might change in the middle of the test ⏎ This is why setting it as host = make it static to this scope
<FromGitter> <bararchy> @bew I mean the host = uri.host part, as in creating a variable
<FromGitter> <bararchy> mem , etc ...
<FromGitter> <bew> I don't have much knowledge on how thigs works exactly, but to my understanding, creating a variable like this won't make any memory allocation, no?
<FromGitter> <bararchy> only referance ?
<FromGitter> <felipeelias> @bararchy @sdogruyol that's interesting, I didn't expect that to happen. Something related to crystal? I mean, I can't think of any way of this value changing between tests
<FromGitter> <sdogruyol> @felipeelias it's how `URI.parse` behaves actually
<FromGitter> <sdogruyol> you can read the source
<FromGitter> <bararchy> You can't but the compiler can ;) ⏎ we are getting ready to have multiple threads working in the background, so other stuff might "work" on this class and change the actual value
<FromGitter> <bew> @bararchy `uri.host` is a string, so yes, there it'll be just a reference (not sure what it is exactly memory-wise though..)
<FromGitter> <bararchy> If so then sure, it;s the best way to just set it in the scope
nikkkk has joined #crystal-lang
<FromGitter> <felipeelias> i guess i'm pretty lost with this concept @bararchy @sdogruyol any place where I can read more about it?
<FromGitter> <sdogruyol> it's all about union types :)
<FromGitter> <bararchy> @felipeelias Are you coming over from Ruby ?
<FromGitter> <felipeelias> @bararchy yeah
<FromGitter> <sdogruyol> i love Ruby
<FromGitter> <sdogruyol> :heart:
<FromGitter> <felipeelias> same here :heartbeat:
<FromGitter> <sdogruyol> i love Crystal too :heart:
<FromGitter> <nik736> Hi @sdogruyol , I have read your multi part implementation for kemal but I am wondering where the parse_multipart method is coming from in your examples? I am not able to use it, thanks for any answer :) New to Kemal and loving it so far
<FromGitter> <sdogruyol> In fact, thanks to Crystal i started love Ruby much more :P
<FromGitter> <sdogruyol> @nik736 hey, thank you!
nikkkk has quit [Quit: Textual IRC Client: www.textualapp.com]
<FromGitter> <codenoid> @bew thanks, hehe, sorry, i rather read the documentation,,
<FromGitter> <codenoid> hehe, my first client app, build with crystal and kemal https://s30.postimg.org/tum9xdfpt/arfa4.png
<FromGitter> <sdogruyol> @nik736 parse_multipart is actually deprecated
<FromGitter> <sdogruyol> check http://kemalcr.com/docs/file_upload
<FromGitter> <bararchy> @felipeelias This feels femiliar haha I had lots of hard time getting from Ruby mind set to Crystal, the big thing is that you need to understand that from the compilers point of view, you need to know exactly what Types are going in to what functions. ⏎ ⏎ So, ⏎ ⏎ ```a = [] of (String | Nil)``` ... [https://gitter.im/crystal-lang/crystal?at=593d2b867503e2b7063090db]
<FromGitter> <bararchy> This is the best example I can think about :)
<FromGitter> <sdogruyol> @codenoid that's great
<FromGitter> <nik736> @sdogruyol oh, okay, thanks!
<FromGitter> <sdogruyol> @codenoid what's it actually doing?
<FromGitter> <sdogruyol> @nik736 it wasn't easy to use so i ditched :P
<FromGitter> <felipeelias> @bararchy @sdogruyol i have to be afk now, but I'll get back to this later :) thanks for the example :)
<FromGitter> <sdogruyol> anytime
<FromGitter> <codenoid> @sdogruyol He is a barber businessman, he wants to create a functioning app so that users can order his online haircut, check whether the outlet is full, etc.
<FromGitter> <sdogruyol> sounds fun :)
<FromGitter> <bararchy> @codenoid What made you choose Crystal ?
<FromGitter> <codenoid> @bararchy Because I like crystal, i like compiled program, simple syntax, performance, and I'm sure crystal can handle this
<FromGitter> <bararchy> Cool :)
<FromGitter> <sdogruyol> @codenoid that's spot on!
<FromGitter> <sdogruyol> :100:
<FromGitter> <bew> Nice work! I guess crystal is used on server side only?
<FromGitter> <sdogruyol> @bew for now :P
<hightower2> Until we get Opal for Crystal :)
<FromGitter> <bararchy> I Created an SSL Cipher scanner which you can catagorize as CLI tool :) so not only server side
<FromGitter> <bew> or wasm :P
rohitpaulk has joined #crystal-lang
<FromGitter> <bararchy> also a quick run thourgh http://crystalshards.xyz shows really cool stuff
<FromGitter> <bew> @bararchy yeah I knon, my sentence was in the context of @codenoid project!
<FromGitter> <bararchy> Ohhh
<FromGitter> <bararchy> Sorry :)
<FromGitter> <bew> don't worry (:
Philpax__ has joined #crystal-lang
<FromGitter> <bew> @jwoertink no there's no way to do that, JSON macro helpers aren't very flexible
jhass has quit [Ping timeout: 240 seconds]
DeBot has quit [Ping timeout: 240 seconds]
asterite has quit [Ping timeout: 255 seconds]
DeBot has joined #crystal-lang
asterite has joined #crystal-lang
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
jhass has joined #crystal-lang
<FromGitter> <bararchy> btw, can someone autogenerate my bindings to libfann (fann) using the crystal_lib project ? I can't seem to be able on my machine :) ⏎ Just need the text as gist or something ⏎ https://github.com/crystal-lang/crystal_lib
<FromGitter> <bararchy> ```@[Include("fann.h")] ⏎ @[Link("fann")] ⏎ lib LibPCRE ⏎ end ⏎ ``` [https://gitter.im/crystal-lang/crystal?at=593d35a731f589c64f971a2f]
hightower4 has joined #crystal-lang
hightower3 has quit [Ping timeout: 240 seconds]
jhass has quit [Ping timeout: 240 seconds]
DeBot has quit [Ping timeout: 255 seconds]
jhass has joined #crystal-lang
Swey_Hey has joined #crystal-lang
Swey_Hey has quit [Quit: Going offline, see ya! (www.adiirc.com)]
DeBot has joined #crystal-lang
DeBot has quit [Ping timeout: 255 seconds]
DeBot has joined #crystal-lang
onionhammer1 has quit [Ping timeout: 255 seconds]
greengriminal has joined #crystal-lang
cyberarm has quit [Ping timeout: 260 seconds]
onionhammer has joined #crystal-lang
<FromGitter> <bew> @bararchy can't get it to work either, did you tried libgen? https://github.com/olbat/libgen
<FromGitter> <bararchy> isn't libgen just a wrapper around crystal_lib ?
splitty_ has joined #crystal-lang
<FromGitter> <bew> oh right, I thought it was a different project..
splitty__ has joined #crystal-lang
splitty___ has joined #crystal-lang
splitty_ has quit [Ping timeout: 240 seconds]
splitty__ has quit [Ping timeout: 240 seconds]
splitty___ has quit [Ping timeout: 240 seconds]
rohitpaulk has quit [Ping timeout: 255 seconds]
greengriminal has quit [Quit: This computer has gone to sleep]
<hightower2> Does crystal have some kind of a built-in marshaller? Like Ruby's Marshal?
<FromGitter> <bew> If I understand well, Marshal is just a serialization protocol?
<RX14> hightower2, no, use an existing serialization format
<hightower2> bew: yes, language/platform-specific one
<RX14> without a runtime there is no reason to use Marshall because there's no underlying representation
<hightower2> (or at least that's what I am looking for - something that dumps structures in internal format)
<RX14> any representation you create is going to be just as fast
<hightower2> ok, thanks
<RX14> so it makes WAY more sense to use an existing one
<RX14> with an existing ecosystem
<RX14> not create your own for little benefit
<hightower2> Is there a ?. operator like in Groovy? e.g. to write x?.y?.c which is equal to "x.y.c" if x and y are non-nul?
<Papierkorb> hightower2: No, but there's `Object#try`
<FromGitter> <rishavs> How can i forc Kemal to use a specific ip like localhost:3000, instead of 0.0.0.0?
<FromGitter> <rishavs> i am having some issues with my current proxy
<hightower2> Papierkorb, cool, thanks
splitty_ has joined #crystal-lang
splitty__ has joined #crystal-lang
splitty___ has joined #crystal-lang
<FromGitter> <sdogruyol> @rishavs ⏎ ⏎ ```Kemal.config.binding = "127.0.0.1" ⏎ Kemal.config.port = 3000``` [https://gitter.im/crystal-lang/crystal?at=593d6f8b31f589c64f97e913]
splitty_ has quit [Ping timeout: 260 seconds]
splitty__ has quit [Ping timeout: 260 seconds]
splitty___ has quit [Ping timeout: 246 seconds]
<FromGitter> <drujensen> Announcement: I am excited to announce that Kemalyst and Amber have joined forces and we are merging the best of both projects into one framework called Amber. We are replacing the Kemalyst routing and controller with Amber which has a phoenix like routing and rails like controllers. We have renamed the kemalyst-model to granite-orm. We also moved the Kemalyst generators to amber-cmd, Mailers to
<FromGitter> ... quartz-mailer and Jobs to the Amber framework. We are working on a PubSub Websocket integration for a Rails Cable alternative.
<FromGitter> <akzhan> Great news
<FromGitter> <drujensen> You can find all the goodness here: https://github.com/Amber-Crystal
<FromGitter> <drujensen> http://www.ambercr.io
<FromGitter> <akzhan> By the way, how would we organize a Crystal evangelists at the Railsclub Conference of 2017? https://railsclub.ru/en/main
<FromGitter> <rishavs> thanks @sdogruyol
<FromGitter> <sdogruyol> @drujensen @elorest congrats :clap:
<hightower2> Ok silly issue -- I have a Hash of type: Hash(String, Hash(String, Int32 | String) | Hash(String, String)). And even though I clearly see key "tcp" being present in the hash, when I try to access hash["tcp"], it tells me: no overload matches 'Array(String)#[]' with type String
<hightower2> What am I doing wrong?
<jhass> well you apparently actually got an array there
<jhass> got something that reproduces?
<FromGitter> <bew> what gives you `puts typeof(your_hash)` ?
<hightower2> Here is an isolated example that exits with the said error: https://pastebin.com/8eBHcF2H
<RX14> there's an array in the second level of that example hightower2
<RX14> if you changed the last line to config["common"]["config"]["tcp"]
<RX14> that wouldn't work in ruby either
<RX14> crystal needs to prove that methods are valid at compile time
<RX14> and the compiler can't take into account what the hash contains
<RX14> every value of a hash is the same type to the compiler
<RX14> either you want a NamedTuple here or you want to create some kind of object
<RX14> passing schemaful data in hashes is not how you want to do it in crystal
<RX14> and from that example it's pretty clear that the data has a schema
<hightower2> Well, I'm open for suggestions. I want to store config in the way I showed. How should I do that instead of using a Hash?
<jhass> store as in serialze to json or yaml?
<RX14> NamedTuple would be the way most familiar to you
<RX14> but i'd use classes
<hightower2> Ah, of course. I was wondering how did crystal differentiate between hashes and named tuples when both used {...}. I see ":" now.
<hightower2> Hm, how would you use classes without overcomplicating it? Have an example maybe?
<RX14> it's be hard to make it as nice but specifying the config schema would be a lot cleaner
<RX14> and using it would be a lot cleaner
<RX14> i typically load config from JSON files
<RX14> so that makes it easy
<RX14> you just use JSON.mapping or YAML.mapping
<RX14> and load the data from a file
<RX14> however if you have complex types in there
<RX14> that's obviously not possible
<hightower2> Yeah, I tried playing with YAML.mapping but didn't have much success, didn't figure out the use yet. Will get to it over time when I stumble on some working examples.
<RX14> i'd suggest starting with NamedTuple
<hightower2> Sure, I have that now and it's working
<RX14> depends how important this part of the application is
<RX14> presumably you'd rather get onto the domain specific parts of whatever you're building
Philpax__ has quit [Ping timeout: 240 seconds]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/vHySv
<crystal-gh> crystal/master 9db7b50 Ary Borenszweig: Fixed #4549: Parser chokes on `x ** -y`
<crystal-gh> [crystal] asterite closed pull request #4512: .downcase(Unicode::CaseOptions::Fold) using char ranges (master...string-and-char-casefold-using-ranges) https://git.io/vH2bh
<FromGitter> <akzhan> Why it is failed? ⏎ ⏎ https://play.crystal-lang.org/#/r/268n
<FromGitter> <bew> Because `StaticArray#shuffle!` has no type annotation
<FromGitter> <bew> so from the method signature, it can't find the return type
<hightower2> Ah, with NamedTuple I don't have merge!
<FromGitter> <akzhan> Thanks, yes, it is
<FromGitter> <akzhan> A lot of methods in stdlib have no type annotations
<FromGitter> <bew> type annotations must be used only when necessary
<FromGitter> <bew> and it's not necessary in a lot of cases
<FromGitter> <akzhan> As you see it shouldd be in case of returning self, for example
<FromGitter> <bew> yes, but the type inference doesn't go inside methods to try to get their return types
<hightower2> In crystal, ".(args)" is not equivalent to ".call(args)" like it is in Ruby, right?
<hightower2> yeah, doesn't seem so.
<travis-ci> crystal-lang/crystal#9db7b50 (master - Fixed #4549: Parser chokes on `x ** -y`): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/241776533
<DeBot> https://github.com/crystal-lang/crystal/issues/4549 (Parser chokes on `x ** -y`)
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/vHy9c
<crystal-gh> crystal/master 62bf2c0 Sijawusz Pur Rahnama: Enclose types in backticks and italicize argument names
<hightower2> How do I define a function and specify that argument may be SomeType or nil/unspecified? I tried def method( arg1 : SomeType | Nil), but this does not allow me to skip specifying the argument - it seems to require me to pass call method(nil)
<FromGitter> <bew> you can use `def method(arg1 : SomeType = nil)`
<FromGitter> <akzhan> ```def method( arg = nil )```
<FromGitter> <bew> you can use `def method(arg1 : SomeType? = nil)` (added the `?`)
<hightower2> Great, I had two types actuall but T1? | T2? = nil worked
<hightower2> thanks
<jhass> T1|T2? should be equivalent
<FromGitter> <bew> saying `SomeType?` is a shortcut for `SomeType | Nil`
<hightower2> Indeed, works, thanks
<FromGitter> <faultyserver> specifically, `SomeType?` gets re-written as `::Union(SomeType, ::Nil)`, which is slightly different in regards to macros
<FromGitter> <faultyserver> e.g., you can't decompose the type in a macro to get the non-nil type at compile time
<FromGitter> <faultyserver> but that's largely unimportant
<FromGitter> <bew> what do you mean " can't decompose the type in a macro to get the non-nil type" ?
<FromGitter> <faultyserver> if I have a macro call like `add_property SomeType?`, I can't look at that argument in a macro and get `SomeType`
<FromGitter> <bew> are you sure about that?
<FromGitter> <faultyserver> I remember trying to do it for a few days about a month back
<FromGitter> <faultyserver> not definite, but there's no clean way to do it
<FromGitter> <faultyserver> I think you could technically iterate all of the types and specifically ignore `Nil`, but that's really awkward
<FromGitter> <bew> hmm no clean way yes (other that go through types like you said)
<FromGitter> <faultyserver> there's an issue somewhere that explains the re-write, but I can't find it right now
<FromGitter> <bew> https://carc.in/#/r/268s
<FromGitter> <faultyserver> yeah, but what if you have a union of other types? https://carc.in/#/r/268u
<FromGitter> <bew> true!
<FromGitter> <faultyserver> bad example sorry: macro add_property(type) ⏎ {% p type.type_vars.first %} ⏎ end ⏎ ⏎ add_property Int32? | Int64? [https://gitter.im/crystal-lang/crystal?at=593d888ecf9c13503c76b246]
<FromGitter> <faultyserver> I don't even remember why I was wanting to do that in the first place, so it was probably a bad use case for macros anyway :)
<FromGitter> <bew> yeah it gets a call to `|`
<FromGitter> <bew> too bad
<FromGitter> <faultyserver> last example using `Union` explicitly: https://carc.in/#/r/268y
<FromGitter> <bew> this should work, but it doesn't :/ https://carc.in/#/r/2694
<FromGitter> <faultyserver> On another note: I have a project where I'm trying to define types that inherit from a base class with a macro, and then I want to be able to create instances of those types using a single factory. I've got a basic structure set up, but for some reason the type inference doesn't seem to think that the subclasses are actually subclasses of the base: https://carc.in/#/r/2691
<FromGitter> <faultyserver> The important part just being the error that comes out: ⏎ ⏎ ```Overloads are: ⏎ - Hash(K, V)#[]=(key : K, value : V)`````` [https://gitter.im/crystal-lang/crystal?at=593d8a5b02c480e67233b8ea]
<FromGitter> <faultyserver> where `class Nop < Base`
<travis-ci> crystal-lang/crystal#96e7222 (master - .downcase(Unicode::CaseOptions::Fold) using char ranges (#4512)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/241777282
<DeBot> https://github.com/crystal-lang/crystal/pull/4512 (.downcase(Unicode::CaseOptions::Fold) using char ranges)
<hightower2> I need to have a method which increments a Int64 variable by 2 on every call, in atomic/thread-safe way (ignoring the fact that it is thread-safe without doing anything due to crystal's current single-threadedness). Is there something ready-made for that or I am best off protecting variable access with a Mutex?
<hightower2> Looks good, thanks
splitty_ has joined #crystal-lang
splitty__ has joined #crystal-lang
splitty___ has joined #crystal-lang
splitty_ has quit [Ping timeout: 245 seconds]
splitty__ has quit [Ping timeout: 245 seconds]
splitty__ has joined #crystal-lang
splitty___ has quit [Ping timeout: 255 seconds]
splitty__ has quit [Ping timeout: 240 seconds]
<travis-ci> crystal-lang/crystal#62bf2c0 (master - Enclose types in backticks and italicize argument names): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/241782446
<hightower2> faultyserver: maybe I'm missing something - but I see I can #add to an Atomic, but I can't #add and read the new value atomically?
<FromGitter> <faultyserver> I don't think that's something that's physically possible on most machines...
<FromGitter> <faultyserver> It'd be two native instructions at best, right? one to `add` and another to `load`/`mov`/whatever
<hightower2> right, sure
<Papierkorb> hightower2: Use CAS,
<Papierkorb> hightower2: Then you'll know the value, as you've just set it yourself
<FromGitter> <faultyserver> btw, I got my dynamic dispatch of sorts working: https://carc.in/#/r/269y
greengriminal has joined #crystal-lang
<FromGitter> <bew> nice!
<hightower2> How can I prevent error about variable possibly being Nil in this case: https://pastebin.com/uTiW8Vuz
frankpf has joined #crystal-lang
<hightower2> ah my mistake, ignore please
akwiatkowski has joined #crystal-lang
<FromGitter> <bew> hightower2, please, when you share some code, use https://carc.in so we can see the errors without having to try on our own
thews has quit [Read error: Connection reset by peer]
<crystal-gh> [crystal] asterite closed pull request #4535: Fix negative digit precision for `Number#round` (master...jm-number-round) https://git.io/vHMLF
olek_poz has joined #crystal-lang
akwiatkowski has quit [Write error: Broken pipe]
<travis-ci> crystal-lang/crystal#aaf000c (master - Fix negative digit precision for `Number#round` (#4535)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/241808867
<DeBot> https://github.com/crystal-lang/crystal/pull/4535 (Fix negative digit precision for `Number#round`)
splitty_ has joined #crystal-lang
frankpf has quit [Quit: Leaving]
fenicks has joined #crystal-lang
thews has joined #crystal-lang
thews has joined #crystal-lang
thews has quit [Changing host]
olek_poz has quit [Ping timeout: 260 seconds]
<FromGitter> <greenbigfrog> `HTTP::Client.get "https://www.cryptopia.co.nz/api/GetMarket/1298"` ⏎ I can perfectly GET from that API in other langs (rb) and browser etc. ⏎ somehow I'm getting `Error reading file: Connection reset by peer (Errno)` in crystal. ⏎ any ideas what's causing the issue? [https://gitter.im/crystal-lang/crystal?at=593db6f002c480e672345b45]
<oprypin> greenbigfrog, `response = HTTP::Client.get("https://www.cryptopia.co.nz/api/GetMarket/1298", headers: HTTP::Headers{"Connection" => "Close"})`
<oprypin> may be worth bringing this up to include this header by default
<FromGitter> <bew> what is this header for?
<oprypin> i think u can search for it
<FromGitter> <bew> yeah sorry
<FromGitter> <bew> so you don't want keep-alive connection by default?
olek_poz has joined #crystal-lang
<FromGitter> <greenbigfrog> thanks oprypin
<oprypin> what... i'm trying some stuff and it seems like crystal sends this header by default and this addition theoretically changes nothing
<oprypin> but somehow it makes it work
<FromGitter> <greenbigfrog> so wait... is it crystal's fault, or the APIs?
<oprypin> no idea what's going on https://bpaste.net/show/cf5bd7502add
olek_poz has quit [Ping timeout: 240 seconds]
<oprypin> greenbigfrog, i dont think it's either's fault, just some unfortunate interaction between them
<FromGitter> <greenbigfrog> should I bother trying to get it to work (without the extra headers)
<oprypin> well it would probably help the community to get to the bottom of this
<oprypin> oh seems like that page fakes some headers that arent there
<oprypin> yes, crystal does in fact need to add a default "Connection" => "Close"
<jhass> well or keep-alive for the .new style, no?
<oprypin> i dont think so but not sure
<oprypin> why is it such a pain to check what headers im sending
<oprypin> i dont have time to fully confirm this at the moment
nokkoisdumb has joined #crystal-lang
<nokkoisdumb> hello! nokko is dumb and would like to know if there is functionality in the crystal standard library to wait for X many milliseconds. I haven't found anything about that in the docs, but maybe I haven't looked hard enough
<nokkoisdumb> but I am fairly sure that is not what i am looking for
<nokkoisdumb> thank you, kind people.
<jhass> https://crystal-lang.org/api/0.22.0/toplevel.html#sleep%28time%3ATime%3A%3ASpan%29-class-method
<jhass> sleep 500.milliseconds ;)
Kug3lis has joined #crystal-lang
<nokkoisdumb> thank you
<nokkoisdumb> found it while googling
<jhass> yw
<nokkoisdumb> i forgot that it's called sleep in sane programming languages
nokkoisdumb has quit [Quit: Page closed]
cyberarm has joined #crystal-lang
<hightower2> Hey I am looking at msgpack-crystal. In Ruby code I used to do things like "@packer.buffer" and "@packer.clear", but in crystal's implementation I see neither #buffer nor #clear. Any hints?
<FromGitter> <johnjansen> my guess is that they arent implemented but @benoist will know for sure
nokkoisdumb has joined #crystal-lang
<nokkoisdumb> Hello! Is there any way to spawn a process (via spawn do) and route its stdout to the terminal it was launched from?
<hightower2> faultyserver: re. Atomic and returning the new value atomically - I just realized that I can't get the new value back from Atomic#add, but Atomic#add does return the old value, so if I do something like x = atomic.add(2) + 2, I have the correct/new value in 'x'
<hightower2> johnjansen: thanks, I've emailed him to check
<FromGitter> <bew> `spawn` doesn't spawn a process, it spawns a Fiber, to spawn a process, use `Process.run`, see the documentation, you'll see what you need
<FromGitter> <bew> @nokkoisdumb ^
<FromGitter> <bew> @hightower2 emailed? why not open an issue on his repo ?
<FromGitter> <johnjansen> actually he is a member of the room i think
<hightower2> If he responds, great :)
<nokkoisdumb> yeah, i was being silly
<nokkoisdumb> just needed to yield to the fibre
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
<crystal-gh> [crystal] Sija opened pull request #4551: Few small fixes (master...few-small-fixes) https://git.io/vHSfh
fenicks has left #crystal-lang [#crystal-lang]