jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.18.7 | Fund Crystals 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
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/v6kes
<crystal-gh> crystal/master 7ae7978 Ary Borenszweig: Fixed #3082: Crash when doing exit/NoReturn in ensure....
onec has joined #crystal-lang
onec has quit [Client Quit]
Philpax has quit [Ping timeout: 252 seconds]
Philpax has joined #crystal-lang
kulelu88 has quit [Quit: Leaving]
<adam12> I'm yet to try this but has anybody done HTTP over unix sockets with Crystal?
<adam12> asterite: Thanks. I was just looking at docs now.
<adam12> I wonder if there is a nice way to have local client/daemon communications without building my own protocol.
<adam12> (ala UnixSockets)
Learod has joined #crystal-lang
Learod has quit [Quit: Page closed]
<FromGitter> <drosehn> Ruby's kernel defines a method called __method__ (or __caller__ ), which gives the name of the current method. Does crystal have some similar feature?
Philpax has quit [Ping timeout: 244 seconds]
<FromGitter> <drosehn> Oops. Hmm. '__method__'
<FromGitter> <drosehn> well, it's the word 'method' with two underscores before it, and two after it!
<FromGitter> <drosehn> I use it for quick debug messages, such as: ⏎ `printf "DBG: ... Called %s.%s\n", self.class, __method__`
Philpax has joined #crystal-lang
onethirtyfive has joined #crystal-lang
onethirtyfive has quit []
piotrb has joined #crystal-lang
<piotrb> What's a good project/build system for crystal? seems like make .. but make .. is so .. 70's ..
<piotrb> any cool new projects trying to fill that gap?
<adam12> crake? tho last time I tried it, it wasn't updated and had build errors.
<foca> piotrb: make
<foca> it works, it's simple, it's straightforward
<foca> there's NO POINT to keep reinventing that wheel (badly)
<piotrb> I guess crystal is less messy .. its a monolithic compilation process so you're not juggling 100's of .o's
<foca> there's a few things in make that are definitely improvable, but I feel like most of the seven hundred reimplementations of make that are around don't really address those issues, but instead are "I don't want to learn make so I'll rewrite it in <insert language>"
vrand has joined #crystal-lang
vrand has quit [Remote host closed the connection]
<crystal-gh> [crystal] asterite pushed 2 new commits to master: https://git.io/v6kO6
<crystal-gh> crystal/master 3e5fa88 Ary Borenszweig: Replaced all `x as T` with `x.as(T)`
<crystal-gh> crystal/master 3e62344 Ary Borenszweig: Removed the deprecated `x as T` syntax
<travis-ci> crystal-lang/crystal#3e62344 (master - Removed the deprecated `x as T` syntax): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/149371001
pawnbox has quit [Ping timeout: 260 seconds]
<piotrb> hmm .. different question .. been looking at C binding generators .. so far came across https://github.com/TechMagister/bindgencr and crystal_lib .. both seem to have issues .. crystal_lib seems more immature ..
<piotrb> is there another?
pawnbox has joined #crystal-lang
onethirtyfive has joined #crystal-lang
piotrb has quit [Quit: Leaving.]
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
emancu has joined #crystal-lang
<emancu> hello! anyone online ?
<emancu> I wonder why is this happening
<emancu> require 'json'
<emancu> expected = { "message" => "Hi!" }
<emancu> body = "{\"message\":\"Hi!\"}"
<emancu> res = JSON.parse body
<emancu> puts expected == res # false
<emancu> puts res == expected # true
<txdv> interesting
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
Philpax has quit [Ping timeout: 240 seconds]
<willl> emancu: you can call #raw on the JSON::Any https://carc.in/#/r/15ap this is what JSON::Any#== does https://github.com/crystal-lang/crystal/blob/master/src/json/any.cr#L238-L241
<emancu> thx willl
<emancu> but still, why if the classes are different, the `==` returns true
mark_66 has joined #crystal-lang
bjz has joined #crystal-lang
matp has quit [Ping timeout: 252 seconds]
Philpax has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
Philpax has quit [Ping timeout: 276 seconds]
<jhass> == is just a method call, it can be implemented however
<jhass> in this case the metamodel is probably just broken though
<jhass> all the .class stuff is just fake
<jhass> ah no, nvm
<jhass> Hash#== doesn't know about JSON::Any, but JSON::Any#== knows about Hash
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
emmanueloga has quit [Ping timeout: 276 seconds]
emmanueloga has joined #crystal-lang
Philpax has joined #crystal-lang
elomatreb has quit [Ping timeout: 250 seconds]
asterite has quit [Ping timeout: 264 seconds]
DeBot has quit [Ping timeout: 264 seconds]
asterite has joined #crystal-lang
elomatreb has joined #crystal-lang
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 240 seconds]
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
zodiak has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
zodiak_ has quit [Ping timeout: 258 seconds]
pawnbox has joined #crystal-lang
DeBot has joined #crystal-lang
soveran has quit [Remote host closed the connection]
mif_ has joined #crystal-lang
soveran has joined #crystal-lang
mif_ has left #crystal-lang [#crystal-lang]
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
trapped has joined #crystal-lang
pawnbox has joined #crystal-lang
ponga has joined #crystal-lang
<asterite> I think JSON::Any should be much dumber, not having `==` and having `to_s` show `JSON::Any([1, 2, 3])` so it's clear it's a different type than the wrapped value
<asterite> That could stop all the confusion around it
<BlaXpirit> +
<asterite> In fact, maybe JSON::Any is a bad idea... if you know what you are doing then it's fine, but otherwise it might not be very intuitive. Better to expose the raw union all the time and let the user deal with casts, which is probably simpler and the compiler can help with errors
<asterite> It's more tedious to reach a node, but maybe it's clear what's going on
<BlaXpirit> that's what i thought initially too. i think JSON::Any is a relatively recent addition, isn't it?
matp has joined #crystal-lang
<BlaXpirit> but it's nice in a way, I'm not sure about it
<FromGitter> <kofno> I'm using JSON:Any right now. I've just trying to get stuff out of it as quickly as possible, so it doesn't wind through all my code.
<BlaXpirit> i hear ya
<BlaXpirit> well it's great for prototyping
<FromGitter> <kofno> Although, if JSON.mapping could be made a little smarter, I wouldn't use it at all.
<FromGitter> <kofno> Actually, that statement isn't entirely true. But I would use it less.
<FromGitter> <kofno> That said, it isn't awful. I'd just prefer a mapping mechanism that is a little more robust.
matp has quit [Ping timeout: 240 seconds]
Philpax has quit [Ping timeout: 258 seconds]
<jhass> what's missing in mapping for you?
pawnbox has quit [Remote host closed the connection]
<FromGitter> <kofno> Let me see if I can describe it for you:
<FromGitter> <kofno> I get jsonrpc messages. If the json has an id field, I'd like to map to the ProcedureCall struct. If the id is absent, then I'd like it to map onto a NotificationStruct.
<RX14> I think JSON::Any should stay
<FromGitter> <kofno> There's another similar use case, but it amounts to "making a decision about which type to map to, based on the content of the JSON"
<FromGitter> <kofno> So, for now, I'm using JSON::Any and case/when
<FromGitter> <kofno> and manually mapping
pawnbox has joined #crystal-lang
<BlaXpirit> this has been brought up before
pawnbox has quit [Ping timeout: 258 seconds]
pawnbox has joined #crystal-lang
<FromGitter> <kofno> I think JSON::Any has a place for these scenarios where mapping isn't a good fit.
trapped has quit [Read error: Connection reset by peer]
<FromGitter> <asterite> @kofno what is exactly the mapping for each of these classes? I think you could use a union in the mapping, but only if the fields are different
<FromGitter> <sdogruyol> Hey all, a nice blog post about Crystal is up at Codeship Blog https://blog.codeship.com/an-introduction-to-crystal-fast-as-c-slick-as-ruby/
<FromGitter> <kofno> a union? For example: `something: { type: ProcedureCall | Notification }` ?
<asterite> Yes, but it will only work if one mapping isn't a subset of the other
<asterite> Mmm... well, not if you use `strict`
<asterite> I'll show
<FromGitter> <kofno> please do
<FromGitter> <kofno> and thanks!
<FromGitter> <asterite> It would really help if you showed what mapping you need :-)
<FromGitter> <asterite> Mmm...
<FromGitter> <asterite> Is it just one of these that you get?
<FromGitter> <asterite> Or an array of them? Or are they inside another object?
<FromGitter> <asterite> For example: https://play.crystal-lang.org/#/r/15b8
<FromGitter> <asterite> but if one type is a subset of the other you'd need to pass `strict: true` after the properties (put them in a hash/named-tuple literal)
<FromGitter> <kofno> OK... that actually helps a lot.
<FromGitter> <kofno> Here's an example of what a procedure call might look like: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ And a notification would be the same structure, but the `id` field is absent. [https://gitter.im/crystal-lang/crystal?at=57a1f6eb836d2d02116075e1]
<FromGitter> <kofno> and params also variable.
<FromGitter> <asterite> Then using strict will probably work
matp has joined #crystal-lang
<FromGitter> <kofno> ok... that's great. I'll play with that tonight.
soveran has quit [Remote host closed the connection]
Oliphaunte has joined #crystal-lang
hangyas has joined #crystal-lang
<hangyas> hi! is there a solution for this: https://carc.in/#/r/15bd ?
<jhass> seems like a bug, feel free to open an issue
<hangyas> ok, thanks
hangyas has quit [Quit: hangyas]
<RX14> jhass, asterite already fixed it
<RX14> on master
<jhass> oh
<RX14> i ran into it
<RX14> there is already an issue
<jhass> should've tested, couldn't be bothered :P
<RX14> just closed
<adam12> I don't see a way to do a scanf style read on IO. Can anybody look at this and see if there is a more optimal way? Could be nothing wrong with this way but I'm curious. https://play.crystal-lang.org/#/r/15bu
<jhass> you mean more efficient in terms of LOC?
<jhass> not sure what a scanf could do any better performance wise
<BlaXpirit> I don't understand the usefulness of this concept anyway
<adam12> Not performance, but reading the delimiter in and then chopping it, and then having to cast to Int32.
<adam12> Was wondering if I could read it in one go, similar to scanf...
<adam12> BlaXpirit: usefulness of netstrings?
<BlaXpirit> yes
<adam12> Socket communication without having to worry about framing.
<adam12> .. how would you handle it? I'm not 100% sold on netstrings
<jhass> in crystal scanf would return huge unions and probably an array
<jhass> so you'd just trade one ugliness for another
<adam12> jhass: Thanks - I'll deal with what I have then.
<BlaXpirit> adam12, 4 bytes length, then the string...
<BlaXpirit> or 7 bits length + 1 bit continuation if u know what i mean
<adam12> BlaXpirit: Ah - I've done that in Ruby, but it eliminates the plain text nature of being able to use socat, etc.
<adam12> but I agree, maybe that's a better solution here.
<BlaXpirit> ok
mark_66 has quit [Remote host closed the connection]
emancu has quit []
triangles has joined #crystal-lang
<adam12> BlaXpirit: You're thinking something like this? https://play.crystal-lang.org/#/r/15bv
<BlaXpirit> adam12, looking great
<adam12> ty
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
Oliphaunte has quit [Remote host closed the connection]
tomchapi_ has joined #crystal-lang
tomchapi_ has quit [Client Quit]
tomchapi_ has joined #crystal-lang
Oliphaunte has joined #crystal-lang
Oliphaunte has quit [Ping timeout: 250 seconds]
matp has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
Oliphaunte has joined #crystal-lang
<crystal-gh> [crystal] asterite opened pull request #3087: Add RandomAccess (master...feature/random_access) https://git.io/v6IHS
matp has joined #crystal-lang
[spoiler] has quit [Ping timeout: 264 seconds]
[spoiler] has joined #crystal-lang
<txdv> is there something like digest (from ruby) in crystal?
<txdv> I need to create some hash
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<txdv> nice, thanks
<txdv> how do I cast a Int32 into a Int8?
<jhass> to_i8
<jhass> >> 12.to_i8
<DeBot> jhass: # => 12 - https://carc.in/#/r/15er
<txdv> is there some document with other to_ methods?
<txdv> i kinda need a UInt8
<jhass> to_u8
<jhass> and yeah, if it's a literal just 12u8
<FromGitter> <splattael> is there a way to define a function in Crystal (a la `extern "C"`) which can be built as shared library then called from C?
<FromGitter> <splattael> I saw https://github.com/crystal-lang/crystal/blob/master/src/main.cr but cannot make it work somehow
<jhass> fun foo will end up as foo in the binary
<FromGitter> <splattael> oh ok, then there must something else which breaks... thanks!
<FromGitter> <splattael> jhass, perfect, thank you! Now, it segfaults which is aehm good somehow :D
<jhass> :D
<FromGitter> <splattael> btw, crystal_lib looks really nice!
<txdv> crystal_lib?
<txdv> o yeah, I have to check that out too
<FromGitter> <splattael> https://github.com/crystal-lang/crystal_lib - generates Crystal from C headers
go|dfish has joined #crystal-lang
willl has quit [Quit: Connection closed for inactivity]
<jhass> asterite: #ruby just found an interesting edgecase in Ruby, fails differently but nonetheless interesting in Crystal too, not sure if worth fixing but sure fun :D https://carc.in/#/r/15f2
<jhass> more fun trying to pass it to a macro https://carc.in/#/r/15f5
onethirtyfive has quit [Remote host closed the connection]
<BlaXpirit> jhass, i think it's just a normal syntax error, nothing fun about passing to macro
jwaldrip has quit [Quit: Connection closed for inactivity]
<BlaXpirit> is unpacking assignment actually not an expression
<jhass> everything should be an expression IMO
onionhammer has quit [Quit: WeeChat 1.0.1]
onionhammer has joined #crystal-lang
tomchapi_ has quit [Quit: Textual IRC Client: www.textualapp.com]
willl has joined #crystal-lang
<BlaXpirit> easy to say :/
<FromGitter> <splattael> jhass, thanks for your help! Now it does not segfault anymore :) Crystal -> Erlang/Elixir (NIF) works :D
<FromGitter> <splattael> messy, but works: https://github.com/splattael/erl_nif.cr
<jhass> great
<FromGitter> <splattael> too drunk to continue.. good night :)
Oliphaunte has quit [Remote host closed the connection]
woodruffw has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/v6LzR
<crystal-gh> crystal/master adc1092 Ary Borenszweig: Fixed some docs not showing
Oliphaunte has joined #crystal-lang
matp has quit [Ping timeout: 258 seconds]
<crystal-gh> [crystal] barisbalic opened pull request #3089: HTTP::Headers{} expects Hash-literal syntax, e.g. `=>` (master...correct-http-header-documentation) https://git.io/v6LVe
Philpax has joined #crystal-lang
bjz_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<travis-ci> crystal-lang/crystal#adc1092 (master - Fixed some docs not showing): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/149610453
<RX14> still no movement on a second opinion on my Multipart PR?
bjz has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]