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
<crystal-gh> [crystal] asterite pushed 4 new commits to master: http://git.io/vUqKd
<crystal-gh> crystal/master beadcda Ary Borenszweig: Document macros and macro methods. Finally!
<crystal-gh> crystal/master ffb4085 Ary Borenszweig: Fixed #641: incorrect macro parsing of char literals
<crystal-gh> crystal/master 6559e88 Ary Borenszweig: Fixed #638: show regex options on `Regex#to_s`, and expose options as enum.
asterite has joined #crystal-lang
<asterite> I just uploaded some docs on macros: http://crystal-lang.org/docs/syntax_and_semantics/macros.html
<asterite> (finally :-P)
<asterite> And here: http://crystal-lang.org/api/
<asterite> check for the Macros module, you can see the list of methods you can invoke in macros
<asterite> If there's something missing or something that's not very clear, let me know :-)
<asterite> I'll also be adding more docs on everything... I think we (specially jhass!) are starting to answer the same questions over and over, so I hope this can make it easier for all of us
<jhass> asterite: mind opping for a moment? I think your os x inserted weird chars into the topic
asterite has quit [Client Quit]
asterite has joined #crystal-lang
<jhass> /mode + jhass ;)
<jhass> er, +o
<asterite> hi
<asterite> Mmm...
<crystal-gh> [crystal] asterite pushed 1 new commit to master: http://git.io/vUqiQ
<crystal-gh> crystal/master 21206c7 Ary Borenszweig: Added links to docs and API in readme
<jhass> oh, /mode #crystal-lang +o jhass actually I guess, I'm afraid if you edit it, it'll just insert those weird spaces again
<jhass> ty
<asterite> :)
<asterite> Question: should the docs about literals for numbers, range, arrays, etc., be in the official docs or in the standard library api?
<asterite> I'm thinking the correct place is the docs
jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.7.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
<asterite> jhass: thanks!
<jhass> yw
<jhass> and I'd say literals are syntax so /docs/
<travis-ci> manastech/crystal#2321 (master - 1b0beb2 : Ary Borenszweig): The build is still failing.
<asterite> Yeah... I'll move the docs for the source to the docs then. I also think with GitBook you can generate a PDF, maybe, so you could read all of that offline... and if the literals are somewhere else then it would be incomplete
<travis-ci> manastech/crystal#2322 (master - 21206c7 : Ary Borenszweig): The build was fixed.
sfcgeorge has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
sfcgeorge has joined #crystal-lang
asterite has quit [Ping timeout: 246 seconds]
wanderer_ has quit [Quit: Page closed]
havenwood has quit [Read error: Connection reset by peer]
sfcgeorge has quit [Quit: Textual IRC Client: www.textualapp.com]
Cidan is now known as zz_Cidan
Tetsumi has quit [Quit: Leaving]
waterlink has quit [Ping timeout: 264 seconds]
JBat has joined #crystal-lang
vikaton has joined #crystal-lang
<vikaton> >> x = Int32.new; puts x
<DeBot> vikaton: Error in line 3: undefined method 'new' for Int32:Class
<vikaton> >> x = String.new; x = 23; p x
<DeBot> vikaton: Error in line 3: wrong number of arguments for 'String::new' (0 for 1, 2, 3)
<vikaton> >> x = String.new "hi"; p x
<DeBot> vikaton: Error in line 3: no overload matches 'String::new' with types String
<vikaton> private methods are written with protected or private?
<vikaton> >> protected def add(x,y);end;
<DeBot> vikaton: Exception: can't execute `p(protected def add(x, y)
<vikaton> >> private def add(x,y);end;
<DeBot> vikaton: Exception: can't execute `p(private def add(x, y)
<vikaton> guess its both :)
vikaton has quit []
willlll has quit [Quit: willlll]
willlll has joined #crystal-lang
willlll has quit [Client Quit]
vikaton has joined #crystal-lang
<vikaton> >> ["daniel","edmund"].map(&:capitalize)
<DeBot> vikaton: Error in line 3: expected a function type, not Symbol
<vikaton> >> ["daniel","edmund"].map(&capitalize)
<DeBot> vikaton: Error in line 3: undefined local variable or method 'capitalize'
<vikaton> >> "hi".captialize
<DeBot> vikaton: Error in line 3: undefined method 'captialize' for String (did you mean 'capitalize'?)
<vikaton> >> "hi".capitalize
<DeBot> vikaton: "Hi"
zz_Cidan is now known as Cidan
JBat has quit [Quit: Textual IRC Client: http://www.textualapp.com/]
JBat has joined #crystal-lang
datanoise has joined #crystal-lang
Cidan is now known as zz_Cidan
canhtak has joined #crystal-lang
BlaXpirit has joined #crystal-lang
BlaXpirit_ has joined #crystal-lang
BlaXpirit has quit [Killed (barjavel.freenode.net (Nickname regained by services))]
JBat has quit [Quit: Computer has gone to sleep.]
<BlaXpirit> from [a,b,c,d], how to get [{a,b},{b,c},{c,d}] ?
<BlaXpirit> welp, each_cons seems to be it in Ruby
<BlaXpirit> now i just get Error read before definition of '__temp_269' for my program, even if it's an empty file
<BlaXpirit> nvm
datanoise has quit [Ping timeout: 272 seconds]
BlaXpirit has quit [Quit: Quit Konversation]
canhtak has quit [Quit: canhtak]
datanoise has joined #crystal-lang
datanoise has quit [Ping timeout: 256 seconds]
HakanD__ has joined #crystal-lang
canhtak has joined #crystal-lang
JBat has joined #crystal-lang
fowl has quit [Ping timeout: 256 seconds]
canhtak has quit [Quit: canhtak]
notfowl has joined #crystal-lang
HakanD__ has quit [Quit: Be back later ...]
<crystal-gh> [crystal] porras opened pull request #645: Enumerable#each_cons(n) (master...each-cons) http://git.io/vUYsd
datanoise has joined #crystal-lang
JBat has quit [Quit: Computer has gone to sleep.]
datanoise has quit [Ping timeout: 276 seconds]
waterlink has joined #crystal-lang
waterlink has quit [Ping timeout: 264 seconds]
canhtak has joined #crystal-lang
notfowl has quit [Excess Flood]
notfowl has joined #crystal-lang
datanoise has joined #crystal-lang
datanoise has quit [Ping timeout: 272 seconds]
datanoise has joined #crystal-lang
datanoise has quit [Ping timeout: 276 seconds]
wanderer_ has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 2 new commits to master: http://git.io/vUO8q
<crystal-gh> crystal/master 1230f08 Sergio Gil Pérez de la Manga: Enumerable#each_cons
<crystal-gh> crystal/master 4cdcf08 Ary Borenszweig: Merge pull request #645 from porras/each-cons...
<crystal-gh> [crystal] asterite pushed 6 new commits to master: http://git.io/vUO8G
<crystal-gh> crystal/master 3fbe6f7 Ary Borenszweig: Make Regex literals use the constructor accepting Regex::Options
<crystal-gh> crystal/master a3c4ea5 Ary Borenszweig: Removed some TODOs
<crystal-gh> crystal/master 5ea2779 Ary Borenszweig: Added `Iterator#of(element : T)` and `Iterator#of(&block : -> T)`
<travis-ci> manastech/crystal#2324 (master - 4cdcf08 : Ary Borenszweig): The build was broken.
<jeromegn> how would I write this in Crystal? A NULL terminated array of NULL terminated char* strings
<travis-ci> manastech/crystal#2325 (master - aa1302b : Ary Borenszweig): The build was broken.
<wanderer_> myarray = [] of UInt8; myarray << "blabla".cstr; myarray << Pointer(UInt8).null
datanoise has joined #crystal-lang
datanoise has quit [Ping timeout: 245 seconds]
canhtak has quit [Quit: canhtak]
bcardiff has joined #crystal-lang
bcardiff has quit [Ping timeout: 240 seconds]
bcardiff has joined #crystal-lang
bcardiff1 has joined #crystal-lang
bcardiff has quit [Ping timeout: 256 seconds]
bcardiff has joined #crystal-lang
bcardiff1 has quit [Ping timeout: 240 seconds]
bcardiff has quit [Ping timeout: 246 seconds]
bcardiff has joined #crystal-lang
<vikaton> >> "A".to_char
<DeBot> vikaton: Error in line 3: undefined method 'to_char' for String
<vikaton> how do I convert a String to a char?
<vikaton> >> "A".to_u8
<DeBot> vikaton: 0
<vikaton> >> "C".to_u8
<DeBot> vikaton: 0
bcardiff1 has joined #crystal-lang
bcardiff has quit [Ping timeout: 264 seconds]
asterite has joined #crystal-lang
<asterite> >> "A"[0]
<DeBot> asterite: 'A'
asterite has quit [Client Quit]
bcardiff1 has quit [Read error: Connection timed out]
<jeromegn> .org
<jeromegn> err
bcardiff has joined #crystal-lang
<jeromegn> >> “A”.ord
<DeBot> jeromegn: Error in line 3: undefined local variable or method '“A”'
<jeromegn> >> ‘A’
<DeBot> jeromegn: Error in line 3: undefined local variable or method '‘A’'
<jeromegn> hmm
<jeromegn> “A”.ord.to_i
<jeromegn> >> “A”.ord.to_i
<DeBot> jeromegn: Error in line 3: undefined local variable or method '“A”'
<jeromegn> ugh
<vikaton> ur quotations are a bit
<vikaton> messed up for the bot
<jeromegn> seems like it
<vikaton> >> "A".ord
<DeBot> vikaton: Error in line 3: undefined method 'ord' for String
<vikaton> ^
<jeromegn> hehe
<vikaton> >> "A"[0]
<DeBot> vikaton: 'A'
<vikaton> >> "A"[0]i see
<DeBot> vikaton: Syntax error in eval:3: unexpected token: i
<jeromegn> .bytes
<vikaton> >> "A".bytes
<DeBot> vikaton: [65]
bcardiff has quit [Ping timeout: 256 seconds]
bcardiff has joined #crystal-lang
BlaXpirit has joined #crystal-lang
datanoise has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]
JBat has joined #crystal-lang
<vikaton> >> Base64.encode("100001")
<DeBot> vikaton: Error in line 3: undefined constant Base64
<vikaton> >> require "base64";Base64.encode("100001")
<DeBot> vikaton: Error in line 3: undefined method 'encode' for Base64:Class (did you mean 'encode64'?)
<vikaton> >> require "base64";Base64.encode64("100001")
<DeBot> vikaton: "MTAwMDAx\n"
<vikaton> >> "hi" *3
<DeBot> vikaton: "hihihi"
waterlink has joined #crystal-lang
sardaukar has joined #crystal-lang
<jeromegn> >> "a"
<DeBot> jeromegn: "a"
<jeromegn> yea
<jeromegn> switched smart quotes off!
<jhass> smart!
waterlink has quit [Quit: Leaving.]
waterlink has joined #crystal-lang
waterlink has quit [Client Quit]
waterlink has joined #crystal-lang
<vikaton> lol
<vikaton> .to_s(2) converts to binary correct?
<jhass> no
<jhass> it converts to a binary string
<vikaton> jhass, shouldnt this effectively convert that string to binary? https://gist.github.com/Vikaton/22a8b03dcb81486a3cdf
<jhass> depends on your definition of binary
sardaukar has quit [Ping timeout: 246 seconds]
<jhass> the to_u8 is most likely harmful if your string has non-ascii chars
<jhass> for only ascii it's simply useless
<vikaton> o
<jhass> >> 'ö'.ord.to_s(2)
<DeBot> jhass: "11110110"
<jhass> >> 'ö'.ord.to_u8.to_s(2)
<DeBot> jhass: "11110110"
<jhass> meh
<jhass> >> '☃'.ord.to_s(2)
<DeBot> jhass: "10011000000011"
<jhass> >> '☃'.ord.to_u8.to_s(2)
<DeBot> jhass: "11"
<vikaton> jhass, does make a difference, the binary produced by that is not right :/
<jhass> maybe it simply mismatches your definition of binary
<vikaton> it doesnt match the "you" version of http://www.binaryhexconverter.com/binary-to-ascii-text-converter
<vikaton> and my binary produces weird chars
<vikaton> typing in the binary values my text2binary things of y, o, u individually works
<vikaton> so the problem the binary grouping?
<jhass> padding I guess
<vikaton> 111100111011111110101 vs 011110010110111101110101
<vikaton> oh wow
<jhass> >> "you".chars.map &.ord.to_s(2).rjust(8, "0")
<DeBot> jhass: Error in line 3: no overload matches 'String#rjust' with types Int32, String
<jhass> >> "you".chars.map &.ord.to_s(2).rjust(8, '0')
<DeBot> jhass: ["01111001", "01101111", "01110101"]
<vikaton> It's fixed if I add a 0 in front of each binary value of each word
<jhass> >> "you".chars.map(&.ord.to_s(2).rjust(8, '0')).join
<DeBot> jhass: "011110010110111101110101"
<vikaton> jhass, yeah, I had to add a "0" in the +=
<jeromegn> jhass: any thoughts on translating "A NULL terminated array of NULL terminated char* strings" from C to Crystal? It's supposed to be an array of strings, just not sure how to express it in Crystal
<jeromegn> I did UInt8**
<jhass> jeromegn: wanderer_'s example didn't work?
<jeromegn> oh damn
<jeromegn> I missed that
<jhass> oh you mean read
<vikaton> jhass, what is .rjust?
<jhass> jeromegn: for Crystal -> C what wanderer_ said, for C -> Crystal what I linked last time: https://github.com/jhass/crystal-gobject/blob/master/src/helper.cr#L4
<jeromegn> nice
<jeromegn> trying that
<jhass> vikaton: check the docs
<vikaton> docs or api?
<jhass> Crystal borrowed that method from Ruby
sardaukar has joined #crystal-lang
<vikaton> oh
<jeromegn> jhass: I just copied that PointerIterator class in my project, seems to work fine!
<jhass> yeah, maybe I should upstream it
<jhass> needs a better name though
<jeromegn> or maybe arr = [] of String; arr.from_pointer(pointer)
<jeromegn> well, bad naming again...
<jhass> yeah, main issue is that X** can mean two things, either you have n X* and you know n or it's 0-terminated
<jeromegn> jhass: how do you valgrind with the crystal compiler? I tried: valgrind /usr/local/bin/crystal play.cr
<jeromegn> I got the valgrind intro and then my puts but not the usual debug info
<jhass> I guess /usr/local/bin/crystal is a shell wrapper
<jhass> check what it looks like, setup the environment and invoke valgrind on the binary directly
waterlink has quit [Quit: Leaving.]
<jeromegn> ah, you're right and that sets a bunch of ENV vars
<jeromegn> could be interesting to have a --valgrind option
<jeromegn> in crystal
<vikaton> >> {"A" => "b"}.has_key?("A")
<DeBot> vikaton: true
<jeromegn> given the structs are empty in the .h files.. I won't be able to find out the size of them unless I do a small C script to determine them eh?
<jhass> I guess
<jeromegn> oh damn
<jeromegn> apaprently empty structs are impossible
<jeromegn> I just found the true thing
<jhass> reminds me of https://github.com/ryanmjacobs/c
<jeromegn> hmm what the hell does that mean in a C struct? "unsigned is_command : 1;"
<jeromegn> >> hello :: 1
<DeBot> jeromegn: Syntax error in eval:3: expecting token 'CONST', not '1'
<jeromegn> UInt8[1]
<jeromegn> maybe
<notfowl> Bitfield
<jhass> so it's just a bool I guess
canhtak has joined #crystal-lang
<jeromegn> man, I'm not out of the woods yet!
<notfowl> if the structure uses bitfields your best bet is to handle it as an opaque pointer
<jeromegn> how do i define that?
<jeromegn> type Something?
<jeromegn> hmm, guess not
sardaukar has quit [Quit: sardaukar]
sardaukar has joined #crystal-lang
<jhass> well, same old questions, do you need to access the fields, do you need to allocate it? no & no -> alias to Void*, no & yes -> just figure out the total size and use a single member with the right size
<jeromegn> I need to allocate it
<jeromegn> yea
<jeromegn> that's what I'm doing
<jeromegn> however mongo is being an ass
datanoise has quit [Quit: leaving]
<jhass> so just sizeof it in C and be done with it
notfowl is now known as unclefowl
<jeromegn> jhass: I wish... libmongoc has a lot of "private" stucts
unclefowl has quit [Excess Flood]
<jeromegn> and I can't require the files directly, it raises an error that I can only require mongoc.h directly. so I commented out all those checks and now I can include it without error... however, now it just tells me it's undeclared
notfowl has joined #crystal-lang
<jeromegn> oh wait
<jeromegn> sizeof(struct _mongoc_cursor_t)) is what I'm looking for
<jeromegn> 1280
<jeromegn> woot
<jeromegn> big one
<jhass> indeed
<jhass> btw why do you need to uncomment the checks? just include mongo.h
<crystal-gh> [crystal] asterite pushed 10 new commits to master: http://git.io/vU3bM
<crystal-gh> crystal/master 8223242 Ary Borenszweig: Added dummy Iterator#each without a block
<crystal-gh> crystal/master 617716f Ary Borenszweig: Added Int `upto`, `downto` and `to` iterators
<crystal-gh> crystal/master 0f086fd Ary Borenszweig: Small fix in macro docs
<jeromegn> love that guy ^
<jeromegn> jhass: I'm not certain... it doesn't work if I just load mongoc.h.
<crystal-gh> [crystal] asterite pushed 2 new commits to master: http://git.io/vU3AM
<crystal-gh> crystal/master 4cd980d Exilor: Added iterators for Matrix...
<crystal-gh> crystal/master fff0654 Ary Borenszweig: Merge pull request #644 from Exilor/master...
<jeromegn> well, I'm not sure how that works
<jeromegn> I mean, he's using the thing around
<jhass> are you sure you need to allocate it?
<jeromegn> I might not be understand well what allocating means
<jeromegn> haha
<jeromegn> cursor :: LibMongoC::Cursor
<jeromegn> would that be allocating?
<jhass> yes, it would
<jhass> in what context do you need that?
<travis-ci> manastech/crystal#2326 (master - e5419da : Ary Borenszweig): The build was fixed.
<jeromegn> jhass: I don't
<jeromegn> I do need to allocate a few things sometimes like LibBSON::Error and stuff
<jeromegn> but I was just starting to get the same valgrind errors as before so I thought I should probably get the paddings right
<jhass> if you don't allocate it yourself, and only ever have pointers to it there are no paddings to get right
<notfowl> ^
<notfowl> Maybe look at other ffi bson uses
zz_Cidan is now known as Cidan
sardaukar has quit [Quit: sardaukar]
<travis-ci> manastech/crystal#2327 (master - fff0654 : Ary Borenszweig): The build is still failing.
<jeromegn> dang it
<jeromegn> all that work!
<BlaXpirit> ?
<jeromegn> BlaXpirit: https://github.com/datanoise/mongo.cr that was the goal all along. he basically did the same thing I wanted to do :) so now there's no need for me to do it.
sardaukar has joined #crystal-lang
sardaukar has quit [Quit: sardaukar]
<crystal-gh> [crystal] porras opened pull request #648: Iterator#cons(n) (master...each-cons) http://git.io/vUskN
notfowl has quit [Changing host]
notfowl has joined #crystal-lang
notfowl has joined #crystal-lang
DerisiveLogic has joined #crystal-lang
JBat has quit [Quit: Computer has gone to sleep.]
willlll has joined #crystal-lang
<willlll> if I have a function that returns a union type of a few things and Int32, but I know in a particular case it’s only going to be the Int32, can I force it down to just be the Int32?
<vikaton> >> "A A".chars.map &.ord.to_s(2).rjust(8, '0')
<DeBot> vikaton: ["01000001", "00100000", "01000001"]
<BlaXpirit> >> 3.step(limit: 5) { |i| print "#{i} " }
<DeBot> BlaXpirit: 3 4 5 3
<BlaXpirit> ummm wat
<BlaXpirit> oh it returns 3
broz has joined #crystal-lang
<jhass> willlll: you can hint the compiler either by something like if x.is_a? Int32; code, raise unless x.is_a? Int32 or by casting (which is just a runtime check in that case) x = foo as Int32
havenwood has joined #crystal-lang
waterlink has joined #crystal-lang
waterlink has quit [Ping timeout: 256 seconds]
Cidan is now known as zz_Cidan
waterlink has joined #crystal-lang
waterlink1 has joined #crystal-lang
waterlink has quit [Ping timeout: 255 seconds]
<vikaton> >> "hello".unpack
<DeBot> vikaton: Error in line 3: undefined method 'unpack' for String
<vikaton> :(
<vikaton> 1000001.to_s(8)
<vikaton> >> 1000001.to_s(8)
<DeBot> vikaton: "3641101"
<vikaton> >> 1000001.to_s(16)
<DeBot> vikaton: "F4241"
<vikaton> >> 1000001.to_s(36)
<DeBot> vikaton: "LFLT"
<vikaton> is there way to convert a binary to string in Crystal?
<BlaXpirit> vikaton, elaborate
<vikaton> BlaXpirit: converting a binary like 01000001 to either 97 or A
<BlaXpirit> >> 0b01000001
<DeBot> BlaXpirit: 65
<BlaXpirit> >> 0b01000001.chr
<DeBot> BlaXpirit: 'A'
<BlaXpirit> >> "01000001".to_i(2)
<DeBot> BlaXpirit: 65
<BlaXpirit> vikaton,
<vikaton> woooow
<vikaton> thanks BlaXpirit
canhtak has quit [Quit: canhtak]
vikaton has quit []
bcardiff has joined #crystal-lang
<crystal-gh> [crystal] porras opened pull request #649: Documentation for most methods in Enumerable (master...enumerable-docs) http://git.io/vUspo
canhtak has joined #crystal-lang
canhtak has quit [Read error: Connection reset by peer]
canhtak has joined #crystal-lang
<notfowl> >> "z". to_i(10+26)
<DeBot> notfowl: 35
wanderer_ has quit [Quit: Page closed]
vikaton has joined #crystal-lang
<vikaton> >> {"a" =>"world"}.length
<DeBot> vikaton: 1
<vikaton> >> x :: String; x+='a'; x
<DeBot> vikaton: Could not open /dev/zero
<vikaton> >> x="a"; x+='a'; x
<DeBot> vikaton: "aa"
BlaXpirit has quit [Quit: Quit Konversation]