<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> 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>
<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>
<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 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>
<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>
<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.
<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)` ?
<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] 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>
<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>
<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
<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?
<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>
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