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
ismaelga has quit []
ismaelga has joined #crystal-lang
orliesaurus has joined #crystal-lang
<shadeslayer> I'm curious, how does one call the equivalent of strip on a string in Crystal
<jhass> >> " b ".strip
<DeBot> jhass: "b"
<shadeslayer> t = gets
<shadeslayer> t.strip
<shadeslayer> that doesn't seem to work for me
<shadeslayer> Error in /tmp/test.cr:3: undefined method 'strip' for Nil
<jhass> yes, gets might return nil
<jhass> in ruby too
<jhass> you need to check it's not nil first
<shadeslayer> how about
<shadeslayer> t = ""
<shadeslayer> t = gets
<shadeslayer> t.strip
<shadeslayer> doesn't work either
<jhass> yes
<shadeslayer> oh?
<jhass> gets still might return nil
<jhass> what the value of t is before doesn't matter
<shadeslayer> so I need to do : t.strip if t
<jhass> for example
<jhass> t.try &.strip is another variant
<jhass> or if t; okay_expected_input; else; puts "Don't press Ctrl+D :("; exit 1; end;
<shadeslayer> funsies
<shadeslayer> neat that it actually has baked in compiler support for making sure you don't shoot yourself in the head
<jhass> ;)
<shadeslayer> I'm quite curious as to how it identifies you don't do that for further calls, but something to look into later
<shadeslayer> ( for eg. at the moment I do : exit unless t and then it doesn't throw any other compile errors for future calls on t)
<shadeslayer> ( otoh if I do : t = t.strip if t and then t.split('') in the next line, it throws out errors )
<shadeslayer> anyway, night, I have to get up early tomorrow
havenwood has quit [Remote host closed the connection]
sferik_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
wanderer has quit [Quit: Page closed]
ponga has quit [Remote host closed the connection]
havenwood has joined #crystal-lang
havenwood has quit []
sferik has joined #crystal-lang
sferik has quit [Read error: Connection reset by peer]
sferik has joined #crystal-lang
ponga has joined #crystal-lang
ponga has quit [Ping timeout: 255 seconds]
ismaelga has quit [Remote host closed the connection]
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ponga has joined #crystal-lang
ponga has quit [Ping timeout: 252 seconds]
ponga has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]
Ven has joined #crystal-lang
Ven has quit [Read error: Connection reset by peer]
Ven has joined #crystal-lang
ponga has quit [Remote host closed the connection]
leafybasil has quit [Remote host closed the connection]
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
leafybasil has joined #crystal-lang
DeBot has quit [Quit: Crystal]
DeBot has joined #crystal-lang
Ven has joined #crystal-lang
sferik has joined #crystal-lang
bcardiff has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 2 new commits to master: http://git.io/h0p5
<crystal-gh> crystal/master 1696e2a Ary Borenszweig: Fixed #491: incorrect parsing of var/call after loc pragma
<crystal-gh> crystal/master d8f8826 Ary Borenszweig: Fixed #492: String#underscore invalid output
asterite has joined #crystal-lang
<travis-ci> manastech/crystal#2157 (master - d8f8826 : Ary Borenszweig): The build passed.
waj has joined #crystal-lang
<jhass> >> "!".match /[!]/
<DeBot> jhass: #<MatchData:0x8A0CFE0 @regex=/[!]/, @code=Pointer(Void)@8A0AF78, @string="!", @pos=0, @ovector=Pointer(Int32)@8A0BFC0, @length=0>
<jhass> mh
<jhass> >> "?".match /[?]/
<DeBot> jhass: #<MatchData:0x94EDFE0 @regex=/[?]/, @code=Pointer(Void)@94EBF78, @string="?", @pos=0, @ovector=Pointer(Int32)@94ECFC0, @length=0>
asterite has quit [Ping timeout: 246 seconds]
DeBot has quit [Quit: Crystal]
DeBot has joined #crystal-lang
weskinner_work has joined #crystal-lang
asterite has joined #crystal-lang
<asterite> I guess we can change MatchData's inspect
<jhass> not what I was testing
<jhass> DeBot: !hangman ruby
<DeBot> ␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣ [] 0/12
<jhass> DeBot: #
<DeBot> ␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣␣ [#] 1/12
<jhass> DeBot: :
<jhass> :/
<jhass> ah, I see why
<jhass> DeBot: a:
<DeBot> ␣␣␣::␣␣␣␣::␣␣␣␣␣␣␣␣ [#a] 2/12
<asterite> DeBot: e
<DeBot> ␣e␣::␣␣␣␣::␣␣e␣␣␣␣␣ [#a] 2/12
<jhass> DeBot: eiuo
<DeBot> ␣e␣::␣O␣␣::u␣e␣␣␣␣␣ [#ai] 3/12
<asterite> What's that?
<jhass> good question :D
<jhass> DeBot: Pnm
<DeBot> Ne␣::POP␣::u␣e␣␣␣␣␣ [#aim] 4/12
<jhass> DeBot: t
<DeBot> Net::POP␣::u␣e␣␣␣␣␣ [#aim] 4/12
<jhass> DeBot: 3
<asterite> lol :-P
<jhass> meh, didn't whitelist numbers
<asterite> Ruby classes and methods?
<jhass> yeah
<asterite> :)
DeBot has quit [Quit: Crystal]
DeBot has joined #crystal-lang
<shadeslayer> heh that's pretty neat
wanderer has joined #crystal-lang
<wanderer> Hi, I get the crash log "Nil assertion failed", the backtrace contains something with Bool, CodeGen#visit and something with Var+ when using the compiler, what's the best way to debug this now? the log doesn't really helped me so far
<jhass> wanderer: on compile?
<wanderer> yes, I'm trying to compile the compiler
<jhass> uh
<jhass> I suppose you changed something in it/stdlib? got the diff between the last working version maybe?
<wanderer> jhass: no, I'm not at home atm and yes, I've changed something in stdlib
<jhass> you probably found a compiler bug
ismaelga has joined #crystal-lang
<wanderer> is there some way to get a better backtrace with line numbers and stuff, or.. well
<jhass> and to debug this we need the code that caused it :/
<wanderer> I don't even know where it goes wrong
<wanderer> on windows I'd use OllyDbg
<jhass> got the whole trace?
<wanderer> but as for this I have no clue where to start searching
<wanderer> as soon as I get home I can paste it
<wanderer> I've changed multiple smaller things in the stdlib for testing and messing around
<asterite> On what os?
<wanderer> I'm using crystal on Ubuntu
<asterite> The problem is that the compiler uses the std, so if you broke something in the std then that might break the compiler in many ways
<asterite> You can try running the specs first, which also test the compiler
<asterite> As for debugging that, the debugging support is non-existent right now :(
<wanderer> the first line says "Nil assertion failed", then there are like 3 lines that contain something with Bool and then there's a whole bunch of CodeGen calls with #visit, Var+ and such
<asterite> Unless we have the full backtrace (or at least those lines) and the changes you made, there's no way we can know what's wrong
<wanderer> can I somehow get the line numbers?
<jhass> yeah sorry, we'll need the code to cause it or at least the full error, "something with" is useless
<jhass> not anymore since you didn't compile the compiler with --debug
<wanderer> that's what I thought
<wanderer> so I'll recompile the compiler with --debug and test it again
<wanderer> then I would get a better crash log?
<jhass> uh, I don't remember if libunwind reads them
<jhass> but worth a try
<wanderer> k, I'll paste it here, too, later
<asterite> I think you then use addr2line or something like that
havenwood has joined #crystal-lang
weskinner_work has left #crystal-lang [#crystal-lang]
<wanderer> btw what ways are there to create static arrays?
<wanderer> dynamic arrays are created with [] of String, correct?
<asterite> Yes
<asterite> You can create static array with new: StaticArray(Int32, 8).new(0)
<asterite> >> StaticArray(Int32, 8).new(0)
<DeBot> asterite: [0, 0, 0, 0, 0, 0, 0, 0]
<asterite> >> StaticArray(Int32, 8).new { |i| i * 2 }
<DeBot> asterite: [0, 2, 4, 6, 8, 10, 12, 14]
<asterite> Or uninitialized
<asterite> >> x :: StaticArray(Int32, 8)
<DeBot> asterite: [134560324, 0, 134515280, 0, 134522612, 1, 0, 1]
<asterite> which can also be written as:
<asterite> >> x :: Int32[8]
<DeBot> asterite: [134560324, 0, 134515280, 0, 134522612, 1, 0, 1]
<asterite> This bot is really useful :)
<wanderer> asterite: thx, are there more possibilities?
<asterite> I don't think so… unless you define new `new` methods on it :)
<asterite> What do you need to do?
<wanderer> also, where does this :: syntax actually come from?
<asterite> Mmm… the language
<asterite> Or do you mean, why did we use that?
<wanderer> atm nothing, yesterday I was testing around a little and I was a kinda confused how I get what I actually want, due to all those different syntax possibilities
<wanderer> yes
<wanderer> there is no such thing in ruby, is there?
<asterite> No, because in Ruby you don't need to declare uninitialized static arrays to efficiently implementing IO
<asterite> Well, they can do it: they do it in C
<wanderer> I find it rather weird, all these ::
<asterite> Mmm… you normally never use that "::", it's a low level unsafe operation to declare an uninitialized variable
<asterite> To create things you use `new`
<asterite> We chose "::" because it was free in the Ruby grammar, kind of…
<asterite> Ruby grammar already occupies many symbols...
<asterite> In ruby you can actually do: x = 1; x::abs
<asterite> but we don't like that, "::" is for namespace, "." is for method call
<wanderer> I'm used to C and when seeing crystal, all these different initialisation methods, also structs, records, staticarrays, arrays paired with compiler magic are not easy to get going with
<asterite> Mmm… there isn't much compiler magic, really
<asterite> In C you do: `int value;`. That is the same as `value :: Int32` in crystal, only different syntax
<asterite> Or in C: `int value[8];`, in crystal: `value :: Int32[8]`
<wanderer> I've read through some of the blog entries and it seems there are like 3 or 4 ways to create Closures, with compiler magic I also mean that UInt32[8] decays to StaticArray.new(UInt32, 8)
<wanderer> *StaticArray(UInt32, 8).new
<asterite> Ah… well, we could remove that syntax, we only added it so writing C bindings is easier and shorter
<asterite> Otherwise: fun atoi(str : Pointer(UInt8)) : Int32
<asterite> A bit long, but still doable
<asterite> I think Ruby also has 3 or 4 ways to create closures, maybe more
<wanderer> yes, it is easier, but as the documentation of course still lacks, it's not easy yet to get a hang of it
<asterite> I know :(
<asterite> Mmm… did you program in Ruby before?
<wanderer> e.g. there are no docs for StaticArrays yet, so there is no real overview over all the syntactical possibilities which is why they all float through your head halfway and you can't dive into crystal that well :P
<wanderer> once some time ago, normally I use C, x86/x64 asm and javascript
<asterite> Yes… I'm slowly adding documentation, but it's a lot of work, there are many classes and methods
<asterite> I think it's easier to understand crystal if you know ruby (of course). About closures, I think there are only two ways in crystal: the ->{ … } syntax and captured blocks
DeBot has quit [Quit: Crystal]
DeBot has joined #crystal-lang
<wanderer> It's a cool language that's why I'm trying to dive into it and also to contribute, it's not easy yet, though, if you aren't that familiar with Ruby
<wanderer> I also find the syntax has many possibilies overall, but again for example `..` and `...` aren't documented yet, too, if you don't know them, using Crystal to a bigger extent is kind of hard
<asterite> Yes, we need to document those
<asterite> The other day I started documenting blocks, but I feel like there are lots of blogs and websites out there describing how ruby blocks work, so it feels like duplicated work
<asterite> However, I think we should nonetheless document them from the beginning, as if you don't know them
<wanderer> what is actually that `bc_flags`-file that gets created when compiling something? also what are `.crystal` and `.build` for?
<asterite> In .crystal we store .bc (llvm bitcode) and .o files from previous compilations. So if an llvm module we generate didn't change from the previous run, we reuse the .o file
<asterite> For example compiling the compiler the first time takes about 10 seconds, and the second one about 6 seconds without changes. If you introduce changes, only the affected files get recompiled
<asterite> The bc_flags holds the llvm flags for which those '.bc' are valid. For example if you compile a program, the recompile it with some other link flags or target triple, we can't reuse the cached one (now that I think it, I'm not sure about this)
<asterite> Finally, the .build holds the newly created compiler, so you can try it (this only applies to the compiler project)
<asterite> when you do bin/crystal it will use .build/crystal if available, or the one installed in your machine
<wanderer> so it's hardcoded where the intermediate files are put during compilation?
<wanderer> when using gcc you would create a /obj/-folder yourself and make gcc emit files to that directory
<asterite> We think it's simpler if the user doesn't have to deal with all of that
havenwood has quit []
<wanderer> ok
<wanderer> >> module SomeModule; class SomeType; end; def some_method; 1; end ; end; include SomeModule; some_method
<DeBot> wanderer: 1
<wanderer> docs say, it's the same as SomeModule.some_method
<wanderer> >> module SomeModule; class SomeType; end; def some_method; 1; end ; end; SomeModule.some_method
<DeBot> wanderer: Error in line 3: undefined method 'some_method' for SomeModule:Class
<asterite> Ah, right, the docs are wrong
<wanderer> does it need an `extends self` or how would SomeModule.some_method work?
<asterite> Yes, it needs and `extend self` or make the method a class method
<asterite> but SomeModule.some_method doesn't work, the doc should say "OK" but nothing else
<wanderer> it says `some_method # OK, same as SomeModule.some_method` so I expected SomeModule.some_method to work
<asterite> Yeah… but there's no equivalent really
<wanderer> yeah, got that now, elsewise it would need an extend, I interpreted the snippet wrongly
havenwood has joined #crystal-lang
<wanderer> for someone who's new to ruby's extend and include , it's kind of unclear what would work and what not
<wanderer> especially with that comment `# OK, same as SomeModule.some_method`
<jhass> Rubys toplevel is basically Object.new.instance_eval { top level code here }, Crystal only fakes that
<asterite> Yes
<asterite> There, I just changed the docs
jhass has quit [Quit: Bye]
jhass has joined #crystal-lang
shama has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
knoopx has joined #crystal-lang
Ven has joined #crystal-lang
knoopx has quit [Remote host closed the connection]
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
asterite1 has joined #crystal-lang
asterite has quit [Ping timeout: 264 seconds]
wanderer has quit [Quit: Page closed]
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sferik has joined #crystal-lang
asterite1 has quit [Quit: Leaving.]
asterite has joined #crystal-lang
asterite_ has joined #crystal-lang
asterite has quit [Ping timeout: 256 seconds]
leafybasil has quit [Remote host closed the connection]
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
havenn has joined #crystal-lang
havenwood has quit [Ping timeout: 245 seconds]
sferik has joined #crystal-lang
waj1 has joined #crystal-lang
waj has quit [Ping timeout: 250 seconds]
eli-se has joined #crystal-lang
<eli-se> hi :3
ismaelga has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
bcardiff1 has joined #crystal-lang
bcardiff has quit [Ping timeout: 250 seconds]
leafybasil has quit [Ping timeout: 246 seconds]
waj has joined #crystal-lang
ismaelga has joined #crystal-lang
waj1 has quit [Ping timeout: 252 seconds]
ponga has joined #crystal-lang
bcardiff1 has quit [Quit: Leaving.]
eli-se has quit [Quit: Leaving...]
ponga has quit [Read error: No route to host]
eli-se has joined #crystal-lang
bcardiff has joined #crystal-lang
bcardiff1 has joined #crystal-lang
bcardiff has quit [Read error: Connection reset by peer]
ponga has joined #crystal-lang
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
wanderer has joined #crystal-lang
<wanderer> hi, here's an excerpt of the crash log: http://pastebin.com/F9r3vt3R
sferik has joined #crystal-lang
bcardiff1 has quit [Quit: Leaving.]
<wanderer> asterite_: seen it?
<asterite_> Ah, I just see it. But without your changes I can't debug anything
<wanderer> asterite_: I could zip them for you, or got any tips so I can debug it?
<asterite_> Mmm... you can fork the repository and do changed in a branch, and then I can checkout that branch
<asterite_> You'd need to understand how the compiler works. It seems a variable lacks a type for some reason
<wanderer> can I somehow output the name of that variable or the line?
bcardiff has joined #crystal-lang
<asterite_> Yes, just before the line ir crashes do: pp var, pp var.location
<asterite_> I mean, `pp var; pp var.location`
<wanderer> err, what line?
<wanderer> I don't even know on what line it actually crashes
bcardiff has quit [Quit: Leaving.]
<asterite_> Mmm... check the backtrace
<asterite_> in some place it does var.type or something, in the backtrace you have the method names
<asterite_> The paste is gone :(
<asterite_> >> ([] of String).each { |x| x.match(/a/); break }
<DeBot> asterite_: Program terminated abnormally with error code: 139
<wanderer> asterite_: http://pastebin.com/EZH1akaZ
<asterite_> Look at CodeGenVisitor#visit(node : Var)
<asterite_> That's in codegen.cr
<wanderer> what does "+264 [580804896]" mean?
<wanderer> asterite_: also what's "*Crystal::Var+@Crystal::ASTNode#type<Crystal::Var+>:Crystal::Type+ +115 [580804896]" about?
<asterite_> It's the name that we generate for method
<asterite_> That's Var's (or one of its subtypes) method "type", defined in ASTNode, that returns a Type
<wanderer> asterite_: so I should change it to: ` def visit(node : Var) var = context.vars[node.name]? if var pp var; pp var.location`?
<asterite_> Yes, try
<wanderer> when trying to compile, it says `undefined method 'location' for Crystal::CodeGenVisitor::LLVMVar`
eli-se has quit [Quit: Leaving...]
waj has quit [Quit: Leaving.]
<crystal-gh> [crystal] asterite pushed 4 new commits to master: http://git.io/h2zh
<crystal-gh> crystal/master feb5be8 Ary Borenszweig: Added some docs to Array and StaticArray
<crystal-gh> crystal/master 18395c4 Ary Borenszweig: Fixed: wrong error message
<crystal-gh> crystal/master e1b2575 Ary Borenszweig: Spec: use `inspect` in some expectation messages
leafybasil has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 1 new commit to master: http://git.io/h2wZ
<crystal-gh> crystal/master 405f11d Ary Borenszweig: Fixed #494
<asterite_> Oh, try with node.location
asterite_ has quit [Quit: Page closed]
<travis-ci> manastech/crystal#2158 (master - 07a8d47 : Ary Borenszweig): The build passed.
<travis-ci> manastech/crystal#2159 (master - 405f11d : Ary Borenszweig): The build passed.
ponga has quit [Quit: Leaving...]
ponga has joined #crystal-lang