asterite changed the topic of #crystal-lang to: #crystal-lang The Crystal programming language | http://crystal-lang.org | Crystal 0.6.1 | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/manastech/crystal - Docs: http://crystal-lang.org/docs/ - API: http://crystal-lang.org/api/ - Logs: http://irclog.whitequark.org/crystal-lang
<shadeslayer> what's the equivalent of fail in crystal?
<havenwood> shadeslayer: Ruby's `fail` is an alias to `raise`, which is available in crystal
<havenwood> shadeslayer: or do you mean something else?
<shadeslayer> havenwood: no, that's what I meant
<shadeslayer> ruby sol.rb 0,06s user 0,00s system 99% cpu 0,069 total , ./sol 0,00s user 0,00s system 88% cpu 0,004 total
<shadeslayer> how fun :)
<havenwood> shadeslayer: :)
<a5i> hmm
<a5i> I have a bot that repeats what u say with a !say command
<a5i> though !say /me yawns prints out the command, and doesnt do what its suposed too
<a5i> ik this is off-topic but, anyone know how to not make that happen? :P
asterite has joined #crystal-lang
<asterite> shadeslayer: I'm curious, what's sol.rb?
<a5i> btw, what does 'raise' mean in Crystal ?
<jhass> a5i: you want to say ACTION whatever
asterite has quit [Client Quit]
<jhass> mh
* jhass test
<jhass> :jhass!~jhass@aeshna.de PRIVMSG #crystal-lang :ACTION test
* jhass shrugs
<jhass> ah, surrounded into "\001" apparently
<a5i> surround what exactly with '\001' ?
<jhass> the message body
<jhass> "\001ACTION #{text}\001"
<a5i> oo
<a5i> No luck :/
<jhass> \001 is an escape sequence
<jhass> that won't get interpreted except in string literals
<shadeslayer> heh, sol.rb was something I was writing for a practice interview test :P
<shadeslayer> btw, ruby has open-uri, to handle all sorts of HTTP get requests, is there a equivalent crystal API?
weskinner_work has joined #crystal-lang
<jhass> no, you have to use HTTP::Client for now
weskinner_work has quit [Ping timeout: 255 seconds]
<shadeslayer> hm
<jhass> well, or write open-uri for Crystal :P
<shadeslayer> :D
<shadeslayer> I really should, maybe over Easter
<shadeslayer> I quite enjoy writing things in Crystal, and it would be nice to have feature parity with ruby wrt stdlib
<a5i> I'm kinda confused as to what "auto" does
weskinner_work has joined #crystal-lang
e_dub has joined #crystal-lang
<a5i> :S
<jhass> it writes your code for you!
leafybasil has quit [Remote host closed the connection]
<a5i> is that an april fools joke?
<a5i> wtf..
<a5i> did april fools come out in a weird font
shama has quit [Quit: (╯°□°)╯︵ɐɯɐɥs]
e_dub has quit [Read error: Connection reset by peer]
e_dub has joined #crystal-lang
<a5i> can someone please tell me if Auto is a joke?
<a5i> its April 2nd here
leafybasil has joined #crystal-lang
leafybasil has quit [Ping timeout: 244 seconds]
ponga has joined #crystal-lang
asterite has joined #crystal-lang
<asterite> a5i: but the post was published on April 1st ;-)
<asterite> However, there is an auto branch and if you try it it does... something
<a5i> I had a feeling it was a joke lol
<a5i> but i cant compile the HEAD version :)
<asterite> Ah, right...
<asterite> Two coworkers of mine fell for the joke
<asterite> I would have expected them not to :-P
<asterite> One said to me "Wow, that's crazy! How did you do it?"
<a5i> what did that script thing do?
<asterite> The thing is, in Argentina the "fool's day" isn't on April 1st, but it has become kind of like an international thing now, I guess
<asterite> It told you "Processing String#succ..." (or whatever method you auto'd) and stuck there forever
<a5i> haha
<asterite> The code for the commit was pretty big, so I guessed nobody would look at it hard: https://github.com/manastech/crystal/commit/46fd17de4964e648192c1f9c8a039088f6520cb0
<a5i> There was a reddit post on it
<a5i> some people fell for it hard lol
<asterite> Yes, I saw it! In fact at about 21hs here I said "ok, joke's over" and put a message on the blog, but then saw the reddit post and thought "well, let's continue the joke for some hours more" :)
<asterite> It seems to still be there: http://www.reddit.com/r/programming
<asterite> One coworker said to me: "But if you cache the generated method, then it might be that another guy checks out the project, runs the compiler and gets a totally different implementation! That's not very good"
<a5i> lmao
<a5i> gotta go now, night !
<asterite> night!
panga has joined #crystal-lang
ponga has quit [Ping timeout: 248 seconds]
panga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
weskinner_work has quit [Ping timeout: 265 seconds]
asterite has quit [Quit: Page closed]
ponga has quit [Remote host closed the connection]
e_dub has quit [Quit: ZZZzzz…]
e_dub has joined #crystal-lang
e_dub has quit [Client Quit]
e_dub has joined #crystal-lang
e_dub has left #crystal-lang ["It's a hard knock life"]
havenwood has quit []
ponga has joined #crystal-lang
sandelius has joined #crystal-lang
<sandelius> can a class extends itself in crystal? e.g class << self
weskinner_work has joined #crystal-lang
<Cassyblanca> Er
<Cassyblanca> Why?
weskinner_work has quit [Ping timeout: 265 seconds]
<sandelius> Cassyblanca useful when creating macros
<sandelius> like in Ruby
canhtak has joined #crystal-lang
ponga has quit [Quit: Leaving...]
ponga has joined #crystal-lang
sandelius has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sandelius has joined #crystal-lang
sandelius has quit [Client Quit]
sandelius has joined #crystal-lang
canhtak has quit [Quit: canhtak]
bcardiff has joined #crystal-lang
leafybasil has joined #crystal-lang
ponga has quit [Quit: Leaving...]
ponga has joined #crystal-lang
sandelius has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sandelius has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]
sandelius has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sillesta has joined #crystal-lang
canhtak has joined #crystal-lang
livcd has joined #crystal-lang
livcd has left #crystal-lang [#crystal-lang]
canhtak has quit [Quit: canhtak]
canhtak has joined #crystal-lang
canhtak has quit [Ping timeout: 245 seconds]
canhtak has joined #crystal-lang
canhtak has quit [Client Quit]
canhtak has joined #crystal-lang
sandelius has joined #crystal-lang
colorisco has joined #crystal-lang
ponga_ has joined #crystal-lang
canhtak has quit [Quit: canhtak]
ponga has quit []
ponga_ is now known as ponga
<colorisco> in ruby this code works
<colorisco> in crystal no
<colorisco> myBA1 = Array.new(topCandidate + 1) {true}
<colorisco> if reolave with myBA1 = Array.new(topCandidate + 2) {true}
<colorisco> if replace with myBA1 = Array.new(topCandidate + 2) {true}
<colorisco> then works correct
<jhass> sorry?
<jhass> please reread what you wrote :)
<jhass> oh, you mean +2 instead of +1 ?
<colorisco> yes
<jhass> what do you mean by "doesn't work"?
<colorisco> try
<jhass> so an index out of bounds
<colorisco> yes
<colorisco> but ruby code works correct
<jhass> it works in Ruby because Ruby is more forgiving about giving the correct size
<jhass> for example a = []; a[1000] = "1" works in Ruby
<jhass> in Crystal it doesn't
<colorisco> ok, understand
<jhass> so that's also true for access
<jhass> a = []; a[1] will give you nil in Ruby
<jhass> in crystal you get the error you're seeing
<colorisco> yes
sandelius has quit [Ping timeout: 250 seconds]
Exilor has joined #crystal-lang
canhtak has joined #crystal-lang
canhtak has quit [Client Quit]
Exilor has quit [Quit: Page closed]
weskinner_work has joined #crystal-lang
havenwood has joined #crystal-lang
canhtak has joined #crystal-lang
canhtak has quit [Quit: canhtak]
canhtak has joined #crystal-lang
odaeus has joined #crystal-lang
<odaeus> Hi everyone, I was wondering if there is a nice way to access an adhoc hash from JSON data, e.g.: `a = JSON.parse(body); a[“query”][“results”][“rate”][0]` This seems to fail because at any point the key/value can be nil or some random type?
<ytti> you could write your own MagicJsonHash
<ytti> which returns NoObject object for key miss
<ytti> which has method_missing which always returns NoObject
<ytti> terrible hack, if you ask me
<ytti> but then your above result would always either return the expected result, or NoObject
<ytti> don't shoot me, please
<odaeus> ytti: heh, thanks, the proper way is to use the JSON mapping function?
<ytti> the proper way is to verify if the data is there, what you expect
<ytti> you could also be a baller and do just
<ytti> begin
sillesta has quit [Ping timeout: 248 seconds]
<ytti> rate = a[“query”][“results”][“rate”][0]
<ytti> rescue
<ytti> rate = nil
<ytti> end
<odaeus> ytti: that’s funny, I didn’t consider that compiler checks could be rescued!
<a5i> uhh, do we have a logo?
<ytti> hohum, disclaimer, i've not tried this in crystal
<ytti> but this isn't compile time at any rate
<odaeus> ytti: I think it is, it’s the type checker saying that it doesn’t know what type the hash is..
<Cassyblanca> a5i: The floating 3D crystal thing, I think
<ytti> odaeus, oh right, i think your'e right
<ytti> odaeus, yes, the type of rate wouldn't be known compiletime, and that is a problem
<a5i> hu
<odaeus> ytti: the error is: undefined method for ‘[]’ for Nil: rate = result[“query”][“results”… with it pointing out that result could be nil.
<ytti> odaeus, yeah problem is that if result[“query”] returns nil
<ytti> odaeus, you're calling nil['foo'] and nill does not have method []
<odaeus> ytti: I can obviously do if.. if.. if.. or use the `json_mapping` (https://github.com/sferik/twitter-crystal/blob/master/src/twitter/user.cr#L5) but I was hoping for some lightweight option. Thanks though.
<ytti> odaeus, my suggestion seems to work just fine
<ytti> k = {
<ytti> "bar" => { "rate" => 42 },
<ytti> }
<ytti> rate = begin
<ytti> k["foo"]["rate"]
<ytti> rescue
<ytti> nil
<ytti> end
<ytti> p rate
<ytti> this prints 'nil'
<ytti> if i change foo to bar, it prints '42'
<jhass> meh, exceptions for control flow
<jhass> you could .try
<jhass> but that doesn't combine well with JSON::Any either I guess
<jhass> er, JSON::Type it is
asterite has joined #crystal-lang
<asterite> >> require "json"; json = JSON.parse(%<{"query": {"results": {"rate": 10}}}>); (((json as Hash)["query"] as Hash)["results"] as Hash)["rate"]
<DeBot> asterite: 10
<asterite> I'd use casts, like `as Hash`
<asterite> You can see it's not that much typing, if it's just a casual json you need to parse. But, as others said, you can use json_mapping. It'll also be more efficient, and you'll probably get better errors
shama has joined #crystal-lang
<asterite> By the way, you can use json_mapping and map only what you need, you don't need to map the whole object
<asterite> ytti: unfortunately your suggestion doesn't work. It works in your example because it's a Hash of Hash, so you can index both, but when you parse JSON it's a union of many types
<asterite> Here:
<asterite> >> require "json"; json = JSON.parse(%<{"query": {"results": {"rate": 10}}}>); json["query"]["results"]["rate"] rescue 0
<DeBot> asterite: Error in line 3: undefined method '[]' for Nil
<a5i> I added this to the quora topic pic: http://i.imgur.com/giqLZvG.png
<asterite> You have to use `as`... but you can just specify the generic type, like `as Hash`, no need to do `as Hash(String, Hash(...))`
<asterite> Quora?
sillesta has joined #crystal-lang
<odaeus> Sorry wa away
<odaeus> And my IRC client has now lost the ability so show me what I'm typing :/
<odaeus> asterite: that kind of casting is what I was looking for, I was trying the colon syntax by mistake.
<a5i> asterite: Quora.com great site
<odaeus> asterite: thanks for the info! I gtg
<jhass> a5i: doesn't show anything without sign up? meh
odaeus has quit [Quit: odaeus]
<jhass> somebody with enough stackoverflow reputation should create the #crystal-lang tag though and if possible reassign #crystal to us :P
<a5i> how much do you need?
<jhass> 1.5k
asterite has quit [Ping timeout: 246 seconds]
<jhass> and we probably need a mod to get crystal
<jhass> or 2.5k apparently
<a5i> we need to ask a rubyist :P
ponga has quit [Remote host closed the connection]
canhtak has quit [Quit: canhtak]
psionski has joined #crystal-lang
<psionski> hey all :)
<psionski> does anybody have an idea where to send a suggestion for a docs improvement?
<psionski> oh ignore that
<psionski> dist server doesn't even have SSL...
<psionski> curl http://dist.crystal-lang.org/apt/setup.sh | sudo bash
<psionski> for the win then
psionski has quit [Client Quit]
bcardiff has joined #crystal-lang
ponga has joined #crystal-lang
ponga has quit [Ping timeout: 264 seconds]
wanderer_ has joined #crystal-lang
DeBot has quit [Quit: Crystal]
DeBot has joined #crystal-lang
leafybas_ has joined #crystal-lang
leafybasil has quit [Ping timeout: 272 seconds]
leafybas_ has quit [Ping timeout: 252 seconds]
sandelius has joined #crystal-lang
sandelius has quit [Quit: Textual IRC Client: www.textualapp.com]
orliesaurus has quit [Excess Flood]
orliesaurus has joined #crystal-lang
sillesta has quit [Read error: Connection reset by peer]
bcardiff has quit [Quit: Leaving.]
colorisco has quit [Quit: colorisco]
ponga has joined #crystal-lang
ponga has quit [Ping timeout: 244 seconds]
bcardiff has joined #crystal-lang
jua__ has joined #crystal-lang
weskinner_work has quit [Ping timeout: 256 seconds]
havenwood has quit []
leafybasil has joined #crystal-lang
jua__ has quit [Quit: Vision[0.9.7-H-20140108]: i've been blurred!]
asterite has joined #crystal-lang
a5i has quit [Quit: Connection closed for inactivity]
asterite has quit [Ping timeout: 246 seconds]
bcardiff has quit [Quit: Leaving.]
a5i has joined #crystal-lang