jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.5.8 | 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> Which you can then convert to this: https://gist.github.com/asterite/0467f974cdfe27ed8f15
<asterite> Um, that last one doesn't compile, nevermin
travis-ci has joined #crystal-lang
<travis-ci> manastech/crystal#1868 (master - 5fe6294 : Ary Borenszweig): The build passed.
travis-ci has left #crystal-lang [#crystal-lang]
asterite has quit [Quit: Page closed]
sferik has joined #crystal-lang
zamith has quit [Ping timeout: 255 seconds]
zamith has joined #crystal-lang
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
filer has quit [Quit: No Ping reply in 180 seconds.]
filer has joined #crystal-lang
sferik has joined #crystal-lang
bcardiff has joined #crystal-lang
leafybasil has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
sferik has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
zamith has quit [Quit: Be back later ...]
<jhass> epitron: did you ever edit your makepkg.conf? If so, any flags changed from the defaults?
CeBot has quit [Quit: Crystal]
CeBot has joined #crystal-lang
<epitron> jhass: i don't think i edited my makepkg.conf -- it looks standard
<epitron> ok, so, using your crystal-git, i get that -fPIC problem building crystal-0.5.8
<epitron> err, sorry, i was building crystal-git
<jhass> I guess you get it always while building crystal
<jhass> does the package I linked let you run the crystal command though?
<epitron> ~/opt/crystal-git-0.5.8.r112.g5fe6294-1-x86_64.pkg/usr/share/doc/crystal/samples $ crystal tree.cr
<epitron> Error while requiring "prelude": can't find file 'prelude'
<epitron> oh wait, this is an arch package
<epitron> lemme install it
<jhass> yup
<jhass> :)
<epitron> $ crystal tree.cr
<epitron> /usr/bin/ld: .crystal//home/epi/opt/crystal-git-0.5.8.r112.g5fe6294-1-x86_64.pkg/usr/share/doc/crystal/samples/tree.cr/main.o: relocation R_X86_64_32S against `*GC::malloc<UInt32>:Pointer(Void)' can not be used when making a shared object; recompile with -fPIC
<jhass> I feared so
<jhass> so what's llvm-cofnig --host-target ?
<epitron> x86_64-unknown-linux-gnu
<jhass> same as mine :/
<epitron> so, why is main.o being build without -fPIC?
<jhass> intel or amd cpu?
<epitron> *built
<epitron> intel
<epitron> Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz
<jhass> we basically have identical setups :/
<epitron> haha
<epitron> weird
<epitron> let me make sure i'm not using a weird llvm
<jhass> dunno, we literally just call the LLVM api with it's defaults
<jhass> it's very similar to like "clang foo.c"
<epitron> oh, so llvm is building the .o files?
<jhass> yeah
<epitron> hmm
<jhass> afaik
<jhass> but pretty sure
<epitron> it is calling `cc` here
<jhass> so, I have an i7, but if that would be what makes the difference... :/
<epitron> here's the full error
<jhass> mmh, I have CC and CXX set to clang/clang++
<jhass> the environment variables
<epitron> ahhh
<epitron> maybe i should try that
<jhass> my /usr/bin/cc is symlinked to gcc though
<epitron> hmm
<epitron> $ which cc
<epitron> /usr/lib/hardening-wrapper/bin/cc
<jhass> uh
<epitron> hardening, eh? :)
<epitron> looks like i installed some security shit
<jhass> that sounds... interesting
<epitron> $ paci hardening-wrapper
<epitron> Name : hardening-wrapper
gr33n7007h has quit [Ping timeout: 244 seconds]
<epitron> Version : 8-1
<epitron> Description : Wrapper scripts for building hardened executables by default
<epitron> Architecture : x86_64
<epitron> ok, i'm taking that out of my path
<jhass> great how the repo actually describes what it does and why :/
<epitron> it works!
<epitron> haha
<epitron> it's just all those buffer overflow workarounds
<jhass> o/
<epitron> it's wrapping everything, including clang{,++}
<jhass> mmh
<jhass> care to experiment a bit? I got an idea
<jhass> do you have local git clone?
<epitron> oh man, this is exciting
<epitron> i just played 2048 :D
<jhass> :D
<epitron> i have a clone, yes
<jhass> okay, can you try adding -fPIC to the line I linked above?
<jhass> and then run make inside the repo
<epitron> ok, sec
<jhass> after reenabling the hardening stuff that is
<epitron> ah yes
<epitron> hmm
<epitron> i added it to the code, but it didn't have -fPIC in the cc output
<epitron> Error: execution of command failed with code: 1: `cc -o /tmp/crystal-run.Ub8D4o .crystal//home/epi/src/crystal/src/ecr/process.cr/main.o -lpcre -lgc -lpthread -lunwind`
<jhass> oh, yes, my bad
<epitron> do i have to rebuild it?
<epitron> without hardening?
<jhass> yes
<epitron> ok
<jhass> exactly
<jhass> and then with hardening do bin/crystal samples/whatever.cr
gr33n7007h has joined #crystal-lang
<epitron> gotcha
gr33n7007h has joined #crystal-lang
gr33n7007h has quit [Changing host]
<jhass> bin/crystal makes sure that the one built by make is used and that the local src/ get required instead of the globally installed ones
<epitron> whoa, that was fast
<epitron> ok, trying
<epitron> hmm
<epitron> how do i install this? should i just put .build/crystal in ~/bin?
<jhass> so it works?
<epitron> it built it with the -fPIC option in the code
<epitron> but i haven't tried to build w/ hardening scripts
<epitron> because i only have one git checkout
<epitron> and i don't wanna wipe out the -fPIC binary :)
<jhass> as said, just do bin/crystal samples/2048.cr
<epitron> oh, true
<jhass> the bin/crystal wrapper makes sure to use the locally compiled one
<epitron> same bug
<jhass> it's in the output though?
<epitron> oh, it's not :(
<jhass> weird
<jhass> did it say "Using .build/crystal"?
<epitron> yep
<epitron> i removed your package
<epitron> the only crystal is that one
<jhass> oh
<jhass> line 209 has another one :)
<epitron> yeah, i just added that :)
<epitron> rebuildingggg
<epitron> ok, same bug, BUT -fPIC is there
<jhass> meh
<epitron> i guess i'll just shut off this hardening stuff
<jhass> so it's really because llvm emits the o files without the flag I guess
<jhass> the cc call just links
<epitron> yeahhh
<epitron> that makes snse
<epitron> +e
<jhass> I guess I'll take a look at what that thing actually does and whether the llvm api has something
<epitron> i'm guessing it's a defense against buffer overflows knowing where to jump
<epitron> random memory layout
<jhass> I could imagine it makes ROP chaines more portable
<epitron> that's what -fPIE does
<epitron> here's some info about the flags: https://wiki.debian.org/Hardening
<epitron> "it requires the executable be built with -fPIE for any .o files that are linked at the end with -pie."
<epitron> i'm going to add PIE :)
<epitron> no dice
<epitron> ah well!
<epitron> i guess i've been using unhardened executables for 30 years
<epitron> why start now, right?
<epitron> ^_^
<jhass> mmh, I found the API method to get the relocation model, but none to set it yet
<epitron> nice!
<epitron> Reloc::PIC_
<epitron> Reloc::DynamicNoPIC
<epitron> Reloc::Static
<jhass> yup
<jhass> thing is I don't see any engine builder stuff in our bindings
<jhass> :P
sferik has joined #crystal-lang
<epitron> ahh
<epitron> good old enginebuilderfactoryadapters
<jhass> well, we use the C API anyway, so gotta find it there first
* jhass hates doxygen
<epitron> ouch
<epitron> i guess that makes sense, since it's all crystal
shama has joined #crystal-lang
<epitron> does C++ have some kind of OOP binding generation stuff?
<epitron> like, if i wanted to make ruby OOP bindings to some C++ lib?
<jhass> mmh, no idea
<epitron> looks like SWIG is still being maintained
<jhass> I guess if we would allow what symbols C++ generates as function names in C bindings, that might actually work
<jhass> it's just neither nice to write not use I guess
<epitron> hahah
<epitron> yeah
<jhass> C API is just much simpler
<epitron> that would be nasty
<epitron> crystal could support C++ names though
<epitron> and convert those to gross-names
<epitron> i bet there are people out there who know a lot about wrapping/binding C++ things in OOP ways
<epitron> if i run across one, i'll tell you :)
<jhass> there was somebody parsing .h files to generate bindings already
<jhass> more PoC state, but let me find the repo
<jhass> never tried those though
<jhass> so don't know how well they work
<jhass> d'oh
<epitron> nice
<epitron> hmm... i wonder if it would be possible to make a REPL
<epitron> similar to how julia does it
<jhass> REPL is kinda hard in a compiled language
<jhass> you got crystal eval for quick stuff
<epitron> julia uses LLVM too though
<jhass> >> "and me"
<CeBot> jhass: "and me"
<epitron> i mean, linking isn't necessary if you just wanna run some code
<epitron> you just jump to it
<jhass> yes, the dynamic analysis is the hard part
<epitron> the memory space should already contain all the crystal stuff
<epitron> oh, is that a necessary step?
<jhass> crystal does a ton of parsing and lexing stuff that has forward dependencies everywhere
<jhass> so as you can see, eval is no problem at all since you have a defiend scope
<epitron> what's a forward dependency?
<jhass> but in a repl you define stuff and then later may define something that affects it
<epitron> oh, okay.. so crystal doesn't have ruby's open classes?
<jhass> >> class Foo; def foo(x) x.to_s; end; Foo.new.foo("hi"); Foo.new.foo(1);
<CeBot> jhass: Syntax error in eval:7: expecting identifier 'end', not 'EOF'
<jhass> it does
<jhass> and that's part of what's making it harder
<jhass> >> class Foo; def foo(x) x.to_s; end; end; Foo.new.foo("hi"); Foo.new.foo(1);
<CeBot> jhass: "1"
<jhass> so, this code is generating two methods on demand
<epitron> ah
<epitron> so it's kinda like julia or psyco
<jhass> when you defined the class, you don't know which ones you need to generate yet
<epitron> generate methods on the fly
<epitron> based on argument type
<jhass> It#s probably possible, yes. Just a lot of effort
<jhass> and there's more important stuff for the moment ;)
<epitron> ok
<jhass> up for another experiment?
<jhass> if so, try adding reloc: LLVM::RelocMode::PIC to the call at https://github.com/manastech/crystal/blob/master/src/compiler/crystal/codegen/target_machine.cr#L12
sferik has quit [Quit: Textual IRC Client: www.textualapp.com]
<epitron> sure, hold on
<epitron> no dice
<jhass> really? :/
<jhass> meh
<epitron> haha
<epitron> agreed
<epitron> conclusion: meh!
<epitron> this is very slick though
<epitron> i'm going to see how many ruby scripts i can port to it :)
<jhass> :)
<epitron> i love how fast the language builds too
<epitron> "make" seems so quick
<jhass> hehe, then don't run make spec
<epitron> haha
<jhass> but it's fast yeah
<epitron> haha.. egrep.cr
<epitron> hmmm
<epitron> sudoku.cr is weird
<epitron> it solves them all instantly, then sits around for a while chewing CPU
<epitron> then quits
<epitron> oh i see, it does it 10 times
<epitron> weird
<jhass> mmh, the samples weren't touched for some time
<jhass> 2048 was my first contribution to crystal though :D
<epitron> nice!
<epitron> this is odd -- i can't convert Time.now.to_f
<jhass> >> Time.now.to_f
<CeBot> jhass: Error in line 3: undefined method 'to_f' for Time (did you mean 'to_i'?)
<jhass> well, nobody added it yet ;)
<epitron> also
<epitron> >> Time.now - Time.now
<CeBot> epitron: -00:00:00.0000010
<epitron> oh, that didn't work before
<epitron> wait
<epitron> oic
<epitron> there's no to_f on the timediff either
<jhass> expect quite a few holes in stdlib still, the upside is that everything is written in crystal, so filling the gaps is actually fun and asterite is very open to including stuff ;)
<epitron> nice
<epitron> i just need to figure out how to make sublime use ruby syntax on .cr files
<jhass> bottom right
<jhass> where it says the current syntax
<jhass> click on it, then on the very top
<epitron> found it
<epitron> View -> Syntax -> Open all with current extension as...
<jhass> or there ;)
<jhass> same menu I guess
<epitron> hahah
<epitron> i'm so not used to building stuff
<epitron> pry is part of how i think now
<epitron> oh nice
<epitron> Int has .hours, .minutes, .days
<epitron> whoa, single quotes are for chars?
<epitron> why not use the ?c format?
<jhass> because it's ugly? :P
<jhass> you'll get used to after some times, in fact more and more ruby people say to always double quote too
<epitron> it's so... not how every other language works though
<epitron> i mean, needing it use a char is a pretty rare thing
<epitron> while porting over old ruby code probably WILL be pretty common
<jhass> C and Java are just two examples that handle it the same way
<epitron> oh yeah :(
<epitron> my two least favorite languages
<epitron> i think all the dynamic languages use '' as strings though
<epitron> hmm
<jhass> Crystal is not a dynamic language though ;)
<epitron> i know, but it's based on ruby!
<jhass> inspired is the better point at this time ;)
<epitron> don't you want to maximize programmer happiness? :)
<epitron> btw, i'm trying to figure out how to do this --
<epitron> for empty hashes use '{} of KeyType => ValueType
<epitron> lol
<epitron> even your error messages do single quote strings ;)
<epitron> come on!
<jhass> >> {} of String => String
<CeBot> jhass: {}
<epitron> i tried that
<epitron> expecting token 'EOF', not 'end'
<jhass> full code?
<epitron> hold on
<jhass> I did fight with the single quotes too in the beginning btw
<epitron> i think that's a pretty annoying feature
<jhass> it really is just better in a compiled, performance aware language to have a char type
<epitron> that's fine
<epitron> ruby's ?c thing worked well
<epitron> (back when ruby still thought a char type was a good idea)
<jhass> ?c did return an integer though
<epitron> true...
<jhass> and as said, I think the syntax is ugly and asterite agrees
<epitron> i mean, you guys are obviously going a slightly different direction
<jhass> ?c was done because String#[] returned integers, really
<epitron> i just think not having single quote strings, and having them do something else, will annoy a lot of people
<epitron> i mean.. your error messages use single quote strings! :)
<epitron> it's natural to see 'x' as a string
<epitron> not a char
<epitron> cognitive ergnomics
<jhass> mmh, I don't think we have for?
<jhass> >> for x in [1, 2, 3]; print x; end
<CeBot> jhass: Syntax error in eval:5: expecting token 'EOF', not 'rescue'
<epitron> hahah
<epitron> that explains it
<jhass> epitron: you can open an issue at github about it, so we get more people to discuss ;)
<epitron> hmm
<epitron> lesspipe(:wrap=>true) do |less|
<epitron> ^
<epitron> no hash args?
<jhass> >> def foo(x); p(x); end; foo(:wrap => true)
<CeBot> jhass: Syntax error in eval:3: expecting token ')', not '=>'
<jhass> nope
<jhass> every argument can be passed as keyword though
<epitron> >> IO.popen
<CeBot> epitron: Error in line 3: undefined method 'popen' for IO:Class
<epitron> :(
<epitron> a keyword?
<jhass> >> def foo(x); p(x); end; foo(x: true)
<CeBot> jhass: Error in line 3: wrong number of arguments for 'foo' (0 for 1)
<jhass> oh, at least I though so
shama has quit [Quit: (╯°□°)╯︵ɐɯɐɥs]
<epitron> >> def foo(x: false); p x; end; foo(x: true)
<CeBot> epitron: Syntax error in eval:3: expecting token 'CONST', not 'false'
<jhass> >> def foo(x=nil); p(x); end; foo(x: true)
<CeBot> jhass: true
<epitron> oic
<epitron> >> def foo(*args); p args; end; foo(1,2,3,4,5)
<CeBot> epitron: {1, 2, 3, 4, 5}
<epitron> >> {}
<CeBot> epitron: Syntax error in eval:3: for empty hashes use '{} of KeyType => ValueType'
<epitron> heehee
<epitron> >> {"a": 5}
<CeBot> epitron: {"a" => 5}
<jhass> >> Tuple.new
<CeBot> jhass: {}
<jhass> >> {1,2,3}
<epitron> >> h = {"a": 5}; h[5] = "lolz"
<CeBot> jhass: {1, 2, 3}
<CeBot> epitron: Error in line 3: no overload matches 'Hash(String, Int32)#[]=' with types Int32, String
<jhass> you can propose to support the implicit hash, but I think it's not very useful in crystal
<epitron> can values be different types?
<epitron> that was pretty useful
<jhass> yes, with a union
<epitron> >> {"a": 5, "b": [6,7,8]}
<CeBot> epitron: {"a" => 5, "b" => [6, 7, 8]}
<epitron> nice
<epitron> is that a union?
<jhass> >> {"a": 5, "b": [6,7,8]}.class
<CeBot> jhass: Hash(String, (Int32 | Array(Int32)))
<epitron> ahhh
<jhass> yup
<epitron> interesting
<epitron> >> {} of String => (Int32 | Array(Int32))
<CeBot> epitron: {}
<epitron> >> {} of String => (Int32 | Array(Int32) | Int(Array32))
<CeBot> epitron: Error in line 3: undefined constant Array32 (did you mean 'Array'?)
<epitron> :D
<jhass> you can then call all methods that are common to those types
<epitron> i see
<epitron> so it's a method dispatch thing
<jhass> if you want to call methods that only one instance has, you have to do something like v = h[key]; v.x if v.is_a? X
<epitron> heh
<epitron> it doesn't support __END__
<jhass> another issue to open at github then ;)
<jhass> I'm sure it's something that would be accepted
<jhass> although it's harder to implement than in an interpreted language
<epitron> lol
<epitron> include? changed to includes? with no alias
<jhass> yes
<jhass> same for starts_with?, ends_with?
<epitron> Regexp changed to Regex
<jhass> they think it's more correct
<epitron> porting ruby code is going to be annoying
<jhass> Regex is probably an accident
<epitron> why not just put compatability methods?
<jhass> it's a different language really
<jhass> it would just give a false impression
<jhass> the syntax is inspired by Ruby, but it's not Ruby
<epitron> Regexp::IGNORECASE changed to Regex::IGNORE_CASE
<jhass> File.read_lines
<epitron> i know, but like -- it saves memory space if i don't have to remember two almost BUT NOT QUITE identical syntaxes :)
<epitron> that's maddening
<epitron> it's like trying to use a mac keyboard when coming from a PC
<epitron> everything is JUST SLIGHTLY off
<epitron> not enough to stop you from working, but enough to keep you out of flow
<jhass> a compatibility layer might be something for https://github.com/manastech/crystal_ruby
<jhass> anyway, as said, open class model
<epitron> i mean, it's just naming
<jhass> you can just make your compatibility layer as a library if you need it that badly ;)
<jhass> Ruby stdlib naming has quite a few inconsistencies though
<epitron> yeah, i agree
<epitron> but it doesn't hurt to have an EXTRA method for the ruby way
<jhass> cargo culting them to a new language is not really a good idea either
<epitron> like alias include?, includes?
<epitron> i understand that you don't want people to think it's ruby
<epitron> but it helps if i don't have to keep looking things up to fix a one char difference :)
<jhass> anyway, I'm not the language designer, asterite and waj are, if you feel strong about any of these points you should open issues at github, we love to discuss ;)
<epitron> ok!
<epitron> in /home/epi/src/crystal/f.cr:152: wrong number of block arguments (2 for 0)
<epitron> breadth_first_scan(root) do |dirname, filename|
<epitron> o_O
<epitron> all my yields supply 2 args
<jhass> ah yes, def a(&block); b(&block); end; doesn't interfere block args properly yet
<jhass> you need to give crystal a hint there:
<jhass> def breadth_first_scan(&block : (String, String) ->)
<jhass> (I think)
<epitron> ok
<epitron> block_spec.cr has some examples
<jhass> yeah
<epitron> &block : Int32 -> Int32
<epitron> does that mean args -> return type?
<jhass> yup
<jhass> if you leave either side of, crystal tries to interfere it
<epitron> i see
<epitron> "U" is a magic type?
<jhass> if the type is unknown (and i think it needs to be a single uppercase letter), it's a template type
<jhass> like generics in java
<epitron> >> s = "string"; s["i"]
<CeBot> epitron: Error in line 3: no overload matches 'String#[]' with types String
<jhass> in this case, this makes it so that the return side doesn't become a union of all the possible return types
<jhass> but instead a method for each possible return type is instantiated
<epitron> i see
<epitron> so it means U(nknown)?
<jhass> it's just a letter
<jhass> could be T or whatever
<epitron> names should mean things :(
<jhass> you capture something there
<jhass> you choose the name
<jhass> R would be better there I guess, like Return type
<epitron> it could be a keyword
<epitron> Type -> return
<epitron> well, something not already used :)
bcardiff has quit [Quit: Leaving.]
<jhass> it's way more generic than that
<jhass> class Foo(T); def foo(x : T); end
<jhass> it really is like a java generic
<jhass> (and yes, java can have generics per method too)
<epitron> i'll have to read up on those
<epitron> i haven't used java in 15 years
<jhass> I'd imagine C++ has something for that too
<epitron> i haven't used C++ in 13 years
<epitron> actually, i used it a bit in december :)
<epitron> baka-mplayer is a nice video player
<epitron> :D
<epitron> i hacked in a couple features
<jhass> >> def foo(&block : -> R); block.class; end; {foo { 1 }, foo { "hi" }}
<CeBot> jhass: {( -> Int32), ( -> String)}
<jhass> >> def foo(&block); block.class; end; {foo { 1 }, foo { "hi" }}
<CeBot> jhass: {( -> Void), ( -> Void)}
<epitron> interesting
<jhass> >> def foo(&block : -> String|Int); block.class; end; {foo { 1 }, foo { "hi" }}
<CeBot> jhass: {( -> Int32), ( -> String)}
<jhass> oh, I expected a union there :D
<epitron> compiler got smarter
<epitron> :D
<jhass> >> def foo(&block : -> R); R.class; end; {foo { 1 }, foo { "hi" }}
<CeBot> jhass: in line 3: undefined constant R
<jhass> mmh
<jhass> >> def foo(x : R); R.class; end; {foo(1), foo("hi")}
<CeBot> jhass: {Class, Class}
<epitron> "def []?" is interesting
<jhass> right, lol
<jhass> yeah, we take care to return less nils so you don't have to resolve the union with nil all the time
<epitron> okay
<jhass> so you have to explicitly request nil if you are not sure and don't want an exception
<jhass> >> def foo(x : R); R; end; {foo(1), foo("hi")}
<CeBot> jhass: {Int32, String}
<jhass> >> def foo(x); x.class; end; {foo(1), foo("hi")}
<CeBot> jhass: {Int32, String}
<jhass> mmh, it really got smarter :P
<jhass> >> def foo(x); [x].class ; end; {foo(1), foo("hi")}
<CeBot> jhass: {Array(Int32), Array(String)}
<epitron> oh wait! you DO have popen!
<epitron> there's bindings to the C library, but no ruby implementation
<epitron> s/ruby/crystal/
<jhass> epitron: well, Process.run can do it's everyday usecases already
<jhass> except for stderr
<jhass> but I plan to add that soon
<epitron> >> LibC.popen
<CeBot> epitron: Error in line 3: wrong number of arguments for 'LibC#popen' (0 for 2)
<epitron> neat
<epitron> Process.run, eh?
<jhass> after we got IO.select working
<jhass> >> Process.run("/bin/cat", "/etc/groups")
<CeBot> jhass: in /usr/lib/crystal/process/run.cr:9: undefined method 'each' for String
<epitron> i don't see Process.run
<jhass> >> Process.run("/bin/cat", {"/etc/groups"})
<CeBot> jhass: /bin/cat: /etc/groups: No such file or directory
<epitron> haha
<jhass> >> Process.run("/bin/cat", {"/etc/group"})
<CeBot> jhass: Process::Status(@pid=53, @exit=0, @output=nil)
<jhass> >> Process.run("/bin/cat", {"/etc/group"}, output: true).output
<CeBot> jhass: ""
<epitron> oh, there it is
<epitron> process/run.cr
<jhass> >> io = StringIO.new; Process.run("/bin/cat", {"/etc/group"}, output: io); io.read
<CeBot> jhass: Error in line 3: wrong number of arguments for 'StringIO#read' (0 for 1, 2)
<jhass> >> io = StringIO.new; Process.run("/bin/cat", {"/etc/group"}, output: io); io.read(8)
<CeBot> jhass: ""
<jhass> and so on
<epitron> >> LibC.popen("ls", "r").read
<CeBot> epitron: Error in line 3: undefined method 'read' for LibC::File
<epitron> how do you read a file?
<jhass> File.read?
<epitron> >> LibC.popen("ls", "r")
<CeBot> epitron: Sorry, I can't let you do that.
<jhass> File.open is there too I think
<epitron> haha
<epitron> i mean, popen returns a LibC::File
<epitron> oh i see
<epitron> >> LibC.fread( LibC.popen("ls", "r") )
<CeBot> epitron: Error in line 3: wrong number of arguments for 'LibC#fread' (1 for 4)
Cassyblanca has left #crystal-lang ["Textual IRC Client: www.textualapp.com"]
<jhass> I think you shouldn't use bindings in application code though
<epitron> yeah, i'll wrap it :)
<jhass> wrap it, if you think it's interesting for stdlib, pull request
<jhass> in doubt, pull request
<jhass> ;)
<epitron> >> IO
<CeBot> epitron: IO
<epitron> so, ruby puts popen on IO
<jhass> what's wrong with Process.run though?
<epitron> CFileIO is where the rest of the stuff is
<epitron> hmm
<epitron> i dunno
<epitron> i like IO.popen beacuse it gives you a file handle
<epitron> so you can read a line at a time
<epitron> streaming output
<jhass> did you see my StringIO example?
<epitron> and it lets you write to its stdin
<epitron> like
<epitron> IO.popen("less", "w") { |less| 100.times { less.puts "yay" } }
<jhass> >> io = StringIO.new; Process.run("/bin/cat, output: io, input: "hi"); io.read(8)
<CeBot> jhass: Syntax error in eval:3: expecting token ')', not 'hi'
<jhass> huh
<epitron> missing a "
<jhass> >> io = StringIO.new; Process.run("/bin/cat", output: io, input: "hi"); io.read(8;5B
<CeBot> jhass: Syntax error in eval:3: expecting token ')', not ';'
<jhass> gosh
<jhass> >> io = StringIO.new; Process.run("/bin/cat", output: io, input: "hi"); io.gets
<CeBot> jhass: nil
<jhass> mmh
bcardiff has joined #crystal-lang
<epitron> IO.popen is pretty nice imo
<jhass> in theory Process.run should cover these usecases
<epitron> i don't wanna mess with StringIOs :(
<jhass> >> r, w = IO.pipe; Process.run("/bin/cat", output: w, input: "hi"); r.read
<CeBot> jhass: Error in line 3: wrong number of arguments for 'FileDescriptorIO#read' (0 for 1, 2)
<epitron> haha
<jhass> >> r, w = IO.pipe; Process.run("/bin/cat", output: w, input: "hi"); r.gets
<jhass> mmh
<CeBot> jhass: Sorry, that took too long.
<epitron> IO.popen("ls") { |output| puts output.read }
<epitron> so simple
<epitron> IO.popen("cat", "w") { |input| input.puts "yay" }
<jhass> >> r, w = IO.pipe; Process.run("/bin/cat", output: w, input: "hi\n"); r.gets
<CeBot> jhass: Sorry, that took too long.
<jhass> >> r, w = IO.pipe; Process.run("/bin/cat", output: w, input: "hi\n"); r.read(1)
<CeBot> jhass: Sorry, that took too long.
<jhass> it actually, works
<jhass> I block something in the sandbox
<jhass> anyway, nothing against a nice abstraction upon it though ;)
<jhass> contributing to and shaping stdlib is part of the fun of being early in this game ;)
<epitron> in /home/epi/src/crystal/f.cr:56: undefined method 'not'
<epitron> :(
<jhass> like I added max_of and variants yesterday
<epitron> max_of, eh?
<jhass> yeah
<jhass> replaces .map(&.x).max and .max_by(&.x).x
<epitron> weird
<jhass> how so?
<epitron> i dunno, the name doesn't sound like it maps
<epitron> it sounds like it just finds the max value
<epitron> "max element of this set"
<epitron> "max_where" maybe makes more sense
<epitron> "max element where the element is the square of itself"
<jhass> well, you call it on the set
<epitron> yeah, but like...
<epitron> i think "_of" isn't the right name
<jhass> probably, I'm not a native speaker after all
<epitron> oh really?
<epitron> where do you hail from? :)
<jhass> _where sounds like _by to me though
<jhass> germany ;)
<epitron> ahh, cool
<epitron> _suchthat? :)
<jhass> heh
<epitron> how about max_map
<epitron> :D
<jhass> it's not really a map
<jhass> more a _find
<jhass> find_max
<jhass> mmh, no
<epitron> assert { [-1, -2, -3].max_of { |x| -x }.should eq(3) }
<jhass> that's just max
<epitron> it transforms the -3 to 3
<jhass> it returns the value of the block
<epitron> oh
<epitron> so, with_max { |v| }
<epitron> wait
<epitron> but the max would be -1 in that case
<jhass> it's .map {|x| -x }.max
<epitron> right
<jhass> without the extra array alloc
<epitron> maxmap :)
<epitron> or map_max?
<jhass> I don't think that's clearer tbh
<epitron> max_of really doesn't sound like what it's doing
<epitron> max_of_mapped_values
<jhass> why not?
<epitron> that's what you mean
<jhass> maximum of these values
<epitron> these values.. which are being transformed (mapped) by the block
<epitron> you're just hoping the user guesses that the block is mapping them
<jhass> dunno, I was hoping for the shortcut syntax, really
<epitron> "max" and "max_of" really sounds like the same thing to me
<epitron> haha
<epitron> it sounds like the real value is the memory savings
<jhass> ;)
<epitron> saving 3 characters isn't really a big deal
<jhass> well, the other case is .max_by(&.x).x
<jhass> where it DRYs up your code and avoids potentially expensive .x a second time
<epitron> wait, what does .x do?
<jhass> whatever, it's a method call
<epitron> Array#x?
<epitron> oh
<jhass> no
<jhass> it's &:
<jhass> except way more powerful
<epitron> yeah, i get that
<epitron> but you have another .x
<epitron> what's the second one do?
<jhass> max_by returns the item that the block returned the highest value for
<jhass> not the highest value itself
<epitron> ok
<jhass> so if you want to get to the highest value itself in ruby
<jhass> you either have to extra array alloc with .map(&:x).max
<jhass> which sucks with many elements
<jhass> or repeat the computation of .x with .max_by(&:x).x
<jhass> which sucks if .x is expensive
<epitron> lol
<epitron> i don't understand what .x means at the end!
<epitron> what are you mapping? an array of integers?
<jhass> and sucks if :x is actually .a_really_long_method_name
<epitron> so "x" is some random method?
<jhass> whatever, it's just the abstract example
<jhass> yes
<epitron> so, for example, strings.max_by(&.size).size?
<jhass> yes
<epitron> ok
<epitron> strings.max_map(&.size) sounds good to me :D
<jhass> highscore = users.max_of(&.score)
<epitron> actually, users.max(&.score)
<epitron> that sounds pretty good to me
<jhass> that returns the user though
<jhass> not their score
<epitron> i think if you pass a block, it should return what max_of does
<epitron> no block returns the user
<epitron> and max_by(&.score) would return the user
<jhass> ArgumentError: wrong number of arguments (1 for 0)
<epitron> users.max(&.score) sounds like you want the score, not the user
<jhass> in ruby
<jhass> ["a", "aa", "aaa"].max(&:size)
<epitron> users.max => "gimme the max user"
<epitron> users.max(&.score) => "gimme the max score
<jhass> well, easy change
<jhass> another pull request ;)
<epitron> users.max_by(&.score) => "gimme the user with the max score"
<jhass> another better place to discuss )
<epitron> hahah
<epitron> i find it frustrating to convince people over pull requests
<jhass> ?
<epitron> look how much back and forth it took me to convince you :)
<epitron> it would be like 50 messages on github
<jhass> happens
<jhass> I don't think that's a bad thing
<jhass> gives you discussion to refer to in the future
<epitron> yeah, that is nice
<jhass> we do that extensively on diaspora
<jhass> works quite well
<epitron> the problem is that if it takes a long time between replies, you can forget what you were talking about :)
<epitron> diaspora is still alive? :O
<jhass> yup
<epitron> i do like technical discussions on github
<epitron> coffeescript was really cool
<jhass> +5k users in the last days ;)
<epitron> they designed the language in issues
<epitron> oh yeah?
<jhass> yeah
<epitron> did you guys drop a new release?
<jhass> fb ToS
<epitron> haha
<epitron> what did FB do now
<jhass> updated the ToS
<jhass> as always
<epitron> dah, no Interrupt exception
<jhass> !reload
<CeBot> Reloaded plugin configuration.
<jhass> !dstats
<CeBot> diaspora* approximately had 27810 active users in the last 30 days and 80862 active users in the last 180 days.
<jhass> :P
<epitron> ^CProgram terminated abnormally with error code: 2
<epitron> how do i rescue that? :)
<jhass> Signal.trap
<epitron> lol
<jhass> yeah, it's no exception yet
<epitron> i'll just let the program blow up
<jhass> it's not easy to do, there's no runtime that could inject stuff
<epitron> i see
<epitron> omfg
<epitron> i got it to build!
<jhass> \o/
<epitron> it loads so FAST!
<epitron> i just get an "index out of bounds" when i acually try to use it
<epitron> --help works tho!
<epitron> >> "hello"[-1]
<CeBot> epitron: Failed to run your code, sorry!
<epitron> >> s = "hello"; s[-1]
<CeBot> epitron: Failed to run your code, sorry!
<epitron> weird
<epitron> >> s = "hello"; s.chars
<CeBot> epitron: Failed to run your code, sorry!
<epitron> >> s = "hello"
<CeBot> epitron: Failed to run your code, sorry!
<epitron> hahah
<jhass> I borked the whitelist, sorry
<jhass> >> "hello"[-1]
<CeBot> jhass: 'o'
<epitron> hmm
<epitron> hashes don't return nil if the key doesn't exist
<epitron> do i use "fetch"?
<epitron> >> h = {"a": 1}; h.fetch("b")
<CeBot> epitron: #{e.class}: Missing hash value: b
<epitron> >> h = {"a": 1}; h.fetch("b", nil)
<CeBot> epitron: nil
<epitron> >> h = {"a": 1}; h.fetch("b", "whee")
<CeBot> epitron: "whee"
<epitron> >> h = {"a": 1}; h.includes?("b")
<CeBot> epitron: Error in line 3: undefined method 'includes?' for Hash(String, Int32)
<epitron> >> h = {"a": 1}; h.include?("b")
<CeBot> epitron: Error in line 3: undefined method 'include?' for Hash(String, Int32)
<epitron> lol wat
<jhass> >> {a: "x"}[:b]?
<CeBot> jhass: nil
<epitron> ohhh
<jhass> #[] raises, #[]? returns nil
<epitron> gotcha
<epitron> so, returning nil is a performance hit?
<jhass> ideally for all interfaces that define #[], I know it does for Array, Hash & MatchData currently
<jhass> no, it's just inconvenient if you're sure that the index is there
<jhass> since you get a union with nil
<epitron> but it's nice to be able to do: "if x = hash[key]"
<jhass> and that has very few methods left
<epitron> check and assign in once!
<epitron> :D
<jhass> you can do that with #[]? just fine
<epitron> i have to type hash[key] twice though
<jhass> no
<epitron> if hash[key]?
<epitron> x = hash[key]
<epitron> no?
<jhass> >> h = {a: "b"}; x if x = h[:a]?
<CeBot> jhass: Error in line 3: undefined local variable or method 'x' (did you mean 'x'?)
<jhass> >> h = {a: "b"}; if x = h[:a]?; x; end
<CeBot> jhass: "b"
<jhass> >> h = {a: "b"}; if x = h[:b]?; x; end
<CeBot> jhass: nil
<epitron> ahhh
<jhass> the modifer-if issue there is probably a bug
<epitron> i was expecting "?" to return bools
<epitron> why not just have [] return nil?
<jhass> it's more often "includes nil" in crystal
<jhass> in fact Foo? is a shortcut to Foo|Nil
<epitron> o_O
<epitron> that's a big semantic change from ruby
<epitron> lol
<jhass> >> def foo(x : String); x; end; foo(nil)
<CeBot> jhass: Error in line 3: no overload matches 'foo' with types Nil
<jhass> >> def foo(x : String?); x; end; foo(nil)
<CeBot> jhass: nil
<jhass> >> def foo(x : String|nil); x; end; foo(nil)
<CeBot> jhass: Syntax error in eval:3: expecting token 'CONST', not 'nil'
<jhass> >> def foo(x : String|Nil); x; end; foo(nil)
<CeBot> jhass: nil
<jhass> last (working) two are the same thing
<epitron> i got an idea.. how about, "hash[key]" returns Foo|Nil, "hash[key]?" returns Bool, and "hash[key]?!" raises exceptions :D
<jhass> turns out you actually know whether your index should exist or not
<jhass> in most cases
<jhass> so I think having the "normal" call the most convenient one is good
<jhass> also I don't get why we would need an explicit variant for Bool
<epitron> well, because you got rid of "includes?"
<jhass> Crystal has the same semantics for truthiness/falsiness as Ruby
<epitron> i actually really like the "hash[key]?" or "array[index]?" instead of "includes?"
<epitron> that's a great idea :)
<epitron> includes is CRAP
<epitron> sorry, i gotta bug report all these ideas
<epitron> man, i'm going to make a repl
<epitron> this is too annoying
<epitron> :D
<jhass> ;)
<jhass> while true; do echo -n "> "; read input; echo "p begin; $input; end" | crystal eval; done
<epitron> mine has history :D
<epitron> and it puts the result AFTER all the putses
<epitron> oh wait, so does yours
<epitron> mine has a => though!
<jhass> well, that's just a echo -n "=>" away
<jhass> yours has Ctrl+D I guess
<epitron> you gotta echo the => after the eval, but before the answer though
<epitron> you'd need a temp variable
<jhass> why can't I echo it before the eval?
<epitron> OMG it has colorize built in! :D
<epitron> this is really nice
<epitron> i like ruby C
<epitron> i really like how i can hack the STDLIB and it's all available instantly
<epitron> i thought i'd have to recompile crystal originally
<epitron> LLVM is awesome
<epitron> so fast
<jhass> unless you turn on the optimization phase :P
<jhass> (bin/crystal build --release)
bcardiff has quit [Quit: Leaving.]
<epitron> oic
<epitron> woohoo, it works!
<epitron> there's still some gross stuff in here, but it finally works
<epitron> i couldn't get colorize working though
<epitron> jhass: thanks for all your help
<epitron> this is an exciting language
<epitron> it really works well
r20 has quit [Ping timeout: 272 seconds]
gr33n7007h has quit [Ping timeout: 265 seconds]
asterite has joined #crystal-lang
<asterite> >> Time.now
<CeBot> asterite: 2015-01-31 11:35:57
asterite has quit [Client Quit]
asterite has joined #crystal-lang
asterite has quit [Quit: Page closed]
travis-ci has joined #crystal-lang
<travis-ci> manastech/crystal#1873 (master - 409b843 : Ary Borenszweig): The build passed.
travis-ci has left #crystal-lang [#crystal-lang]
zamith has joined #crystal-lang
travis-ci has joined #crystal-lang
<travis-ci> manastech/crystal#1875 (master - 81f191e : Ary Borenszweig): The build passed.
travis-ci has left #crystal-lang [#crystal-lang]
bcardiff has joined #crystal-lang
leafybasil has joined #crystal-lang
travis-ci has joined #crystal-lang
<travis-ci> manastech/crystal#1877 (master - 97c4dff : Ary Borenszweig): The build passed.
travis-ci has left #crystal-lang [#crystal-lang]
travis-ci has joined #crystal-lang
<travis-ci> manastech/crystal#1878 (master - d3b1c67 : Ary Borenszweig): The build passed.
travis-ci has left #crystal-lang [#crystal-lang]
travis-ci has joined #crystal-lang
<travis-ci> manastech/crystal#1879 (master - d8149f9 : Ary Borenszweig): The build passed.
travis-ci has left #crystal-lang [#crystal-lang]
bcardiff has left #crystal-lang [#crystal-lang]
zamith has quit [Quit: Be back later ...]
r20 has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
<epitron> Ooo... This would be good in crystal: http://incise.org/tinywm.html
<jhass> shouldn't be much longer, maybe another 50 lines to bidn the C functions
<jhass> though, I'd rather try to do it for wayland ;P
travis-ci has joined #crystal-lang
<travis-ci> manastech/crystal#1880 (master - 8bdc6cd : Ary Borenszweig): The build passed.
travis-ci has left #crystal-lang [#crystal-lang]
travis-ci has joined #crystal-lang
<travis-ci> manastech/crystal#1881 (master - bfb7b6d : Ary Borenszweig): The build was broken.
travis-ci has left #crystal-lang [#crystal-lang]
asterite has joined #crystal-lang
<jhass> asterite: you should add that to package control ;)
<asterite> how to do that?
<jhass> uh
<asterite> Cool, thanks. I'll submit it later
asterite has quit [Ping timeout: 246 seconds]
leafybasil has joined #crystal-lang
drizz_ has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
gr33n7007h has joined #crystal-lang
drizz has quit [Quit: Lost terminal]
drizz_ is now known as drizz
travis-ci has joined #crystal-lang
<travis-ci> manastech/crystal#1883 (master - bc7bca2 : Ary Borenszweig): The build is still failing.
travis-ci has left #crystal-lang [#crystal-lang]
bcardiff has joined #crystal-lang
ryanf has joined #crystal-lang
havenwood has joined #crystal-lang
zamith has joined #crystal-lang
havenwood has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
kgadek has quit [Ping timeout: 264 seconds]
bcardiff has quit [Quit: Leaving.]
Prawnzy has quit [Ping timeout: 264 seconds]
irclogger_______ has joined #crystal-lang
irclogger______ has quit [Ping timeout: 264 seconds]
Prawnzy has joined #crystal-lang
kgadek has joined #crystal-lang
<epitron> hey, i wanna write some C bindings
<epitron> how do i pass a pointer to an array of pointers to strings?
<epitron> Pointer(Pointer(String))?
<jhass> I guess so
<jhass> what's the c function signature?
<jhass> you might want that Slice stuff, I didn't fully checked it yet
<epitron> it's just an exec that takes multiple args
<epitron> slice, eh?
<jhass> Slice is a Pointer with an associated length
<jhass> good for C array stuff I gather
<jhass> or maybe not
<jhass> as said I didn't fully check it out yet
<epitron> >> ["hello", "there"].map(&.cstr).buffer
<CeBot> epitron: Pointer(Pointer(UInt8))@98F5FE0
<epitron> i think that's what i want?
<jhass> I guess so, just try it out :)
<jhass> >> ["hello", "there"].map(&.cstr).to_unsafe
<CeBot> jhass: Pointer(Pointer(UInt8))@9698FE0
<jhass> to_unsafe is called when you just pass the object and it defines it
<jhass> like to_s when you use an object in "#{}"
<jhass> >> {"hello", "there"}.to_unsafe
<CeBot> jhass: Error in line 3: undefined method 'to_unsafe' for {String, String}
<jhass> >> ["hello", "there"].to_unsafe
<CeBot> jhass: Pointer(String)@96C0FF0
<jhass> so I'd try exec a, b.map(&.cstr)
<epitron> >> LibC.system(["ls", "-l"].map(&.cstr).buffer)
<CeBot> epitron: Error in line 3: argument 'str' of 'LibC#system' must be Pointer(UInt8), not Pointer(Pointer(UInt8))
<epitron> oh, i had to change system to UInt8**
<epitron> anyhow, it says "sh: t]@: command not found"
<epitron> apparently it's running a shell too
<jhass> watch trying?
<jhass> >> system("ls")
<CeBot> jhass: true
<jhass> >> `ls`
<CeBot> jhass: ""
<epitron> yeah, but system can only take one arg
<epitron> i want system to take multiple args
<epitron> so i don't have to shell escape stuff
<epitron> or run a shell at all
<jhass> >> Process.run("/bin/ls", {"-a", "/"}).output
<CeBot> jhass: .
<jhass> >> Process.run("/bin/ls", {"-a", "/"}).output.gsub("\n", ",")
<CeBot> jhass: Error in line 3: undefined method 'gsub' for Nil
<jhass> >> Process.run("/bin/ls", {"-a", "/"}).output.not_nil!.gsub("\n", ",")
<CeBot> jhass: Error in line 3: no overload matches 'String#gsub' with types String, String
<jhass> heh
<jhass> >> Process.run("/bin/ls", {"-a", "/"}).output.not_nil!.gsub('\n', ,")
<CeBot> jhass: Syntax error in eval:3: unterminated call
<jhass> >> Process.run("/bin/ls", {"-a", "/"}).output.not_nil!.gsub('\n', ',')
<CeBot> jhass: .
<jhass> anyway
<jhass> Process.run is the way IMO
<epitron> but that captures the output
<epitron> system just runs the command
<epitron> and the command outputs to your terminal
<jhass> >> Process.run("/bin/ls", {"-a", "/"}, output: false).output.not_nil!.gsub('\n', ',')
<CeBot> jhass: #{e.class}: Nil assertion failed
<jhass> >> Process.run("/bin/ls", {"-a", "/"}, output: false).success?
<CeBot> jhass: true