asterite changed the topic of #crystal-lang to: #crystal-lang The Crystal programming language | http://crystal-lang.org | Crystal 0.6.0 | 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
bcardiff1 has joined #crystal-lang
<ponga> jhass: are you still there
<ponga> in ./test2.cr:11: undefined constant T
<ponga> ar2 = Array.new(ar.length)
<ponga> it gets this error using test
<ponga> the commented one
<jhass> ponga: mmh, might be a bug too, try passing nil explicitly as second arg
<ponga> jhass: it worked on ruby
<ponga> ah
<ponga> uh ok
<ponga> ar2 = Array.new(ar.length, true)
<ponga> but it spat out new error now
<ponga> ;p...
<ponga> ar.each_with_index do |val, i|
<ponga> ^~~~~~~~~~~~~~~
<ponga> in ./test2.cr:10: no overload matches 'Array(Bool)#[]=' with types Int32, String
<ponga> Overloads are:
<ponga> - Array(Bool)#[]=(index : Int, value : Bool)
<ponga> ar2[-1] = val
<jhass> yeah, so you create an array of bools and then try to assign a string
<jhass> the most efficient variant would be Array.new(length) {|i| ... } btw
<ponga> so i go like ar2 = Array.new(ar.length, string)
<jhass> Array(String).new(length) actually
<jhass> though I think that has uninitialized memory
<ponga> ar2 = Array(String).new(length)
<jhass> >> Array(String).new(5)
<DeBot> jhass: []
<ponga> its ok to be not optimized
<ponga> its intentional
<jhass> ah, no, that form should be safe
bcardiff1 has quit [Ping timeout: 265 seconds]
<ponga> index out of bounds ... ;p
<ponga> ok size 5
<ponga> manually size
<jhass> >> a = Array(String).new(10); a[1] = "a"
<DeBot> jhass: #{e.class}: Index out of bounds
<jhass> eh, well
<ponga> oh ok
<ponga> so its crystal thing?
<ponga> not my code?
<jhass> yeah
<ponga> gud..
<ponga> relief
<jhass> >> a = Array(String).new(10, ""); a[1] = "a"
<DeBot> jhass: "a"
<jhass> >> a = Array(String).new(10, ""); a[1] = "a"; a
<DeBot> jhass: ["", "a", "", "", "", "", "", "", "", ""]
<ponga> ah hah
<jhass> you really would never do that though
<ponga> never do what
<ponga> 10, "" ?
<jhass> yeah
<ponga> yeah it made my code slower, somehow
<jhass> I think that Rubys arbitrary array indexing isn't adopted is intentional, but I'll ask asterite next time he drops in
<ponga> jhass: i just went to use ar.map_with_index do |val, i|
<jhass> ah, nice
<jhass> didn't even notice that one :P
<ponga> ya
<ponga> it works
<ponga> so i shouldnt pass nil in crystal
<ponga> ;p
<jhass> yeah :P
<jhass> crystal is a good teacher in how to avoid nil in general :P
shama has joined #crystal-lang
<jhass> ponga: mmh, wait, that just does it in place though and creates a copy at the same time
<jhass> you want to drop the assignments and and do Array(length).new {|i| ... } really
<ponga> wow very interesting
<ponga> jhass: i can't 'map_with_index' in ruby
<ponga> but instead map.with_index
<ponga> and is far slower
<jhass> sure ;)
<ponga> jhass: its unoptimized at purpose
<ponga> to compare to push(shift)
<jhass> well, atm it just does useless operations that don't even do anything towards the wanted result though
<jhass> >> a = StaticArray(String).new(5); a[1] = "a"; a
<DeBot> jhass: Error in line 3: wrong number of type vars for StaticArray(T, N) (1 for 2)
<jhass> >> a = StaticArray(String, 5).new; a[1] = "a"; a
<DeBot> jhass: Error in line 3: 'StaticArray(String, 5):Class#new' is expected to be invoked with a block, but no block was given
<jhass> mmh
<jhass> could've been :P
<ponga> jhass: is there array method that checks same elements and just return them
<ponga> rather than arr.uniq
<ponga> i would just want to see the list of dup elements
<jhass> not sure I follow?
<ponga> um
<jhass> mmh
<ponga> jhass:
<ponga> you see
<ponga> 2.2.0-rc1 :008 > arr = [1,1,2,2,3,3,4]
<ponga> => [1, 1, 2, 2, 3, 3, 4]
<ponga> 2.2.0-rc1 :009 > arr.uniq
<ponga> => [1, 2, 3, 4]
<ponga> .uniq omits the dups and just show the uniq ones
<jhass> yeah
<ponga> but there isn't method to show dup ones
<jhass> (why are you on rc1 btw?)
<ponga> hm?
<jhass> got it
<jhass> 2.2.0-rc1
<ponga> it was newest when i installed
<jhass> well, 2.2 was released since :)
<ponga> jhass: i'd want a method that goes like arr.uniq?
<ponga> => [1,2,3]
<jhass> yeah, got it
<ponga> perhaps i should make one
<ponga> and put it in crystal?
<jhass> that exists in neither afaik
<ponga> lol
<jhass> well, not sure it's all that often needed tbh :P
<ponga> yeah, niether
<ponga> i think it could be useful?!
<jhass> what would be a real world application for it?
<ponga> jhass: for example if you have an array of 70 students name
<ponga> and you just want to see the list of number of pupils with same first name
<ponga> not the dup omitted list
<ponga> like 'how many John is in the class'
<ponga> in hash? maybe
<ponga> ==> {"John" => 3}
<jhass> "how many" and "are there any" is quite different
<ponga> like there are 3 john in class
<ponga> i would want how many
<ponga> in hash
<ponga> ==> {"John" => 3, "Eric" => "2"}
<ponga> like this?
<jhass> ary.group_by(&.first_name).map {|k, v| {k, v.size} }
<jhass> I guess
<ponga> jhass: yeah but why not just have single method
<jhass> I never mapped a hash yet in crystal :D
<ponga> in ruby you even have Date#friday?
<ponga> like
<ponga> Time.new.friday?
<ponga> => false
<ponga> lol
<jhass> well, Rubys Time/Date/DateTime classes aren't exactly prime examples for a good API :P
<jhass> >> {a: 1, b: 2, c: 3}.map {|k,v| {k, v*3} }
<DeBot> jhass: [{:a, 3}, {:b, 6}, {:c, 9}]
<ponga> returning number of dups in array in hash format
<jhass> :(
<jhass> >> {a: 1, b: 2, c: 3}.map {|k,v| {k, v*3} }.to_h
<DeBot> jhass: {:a => 3, :b => 6, :c => 9}
<jhass> \o/
<jhass> yeah, don't think you need that often enough tbh
<ponga> jhass: is it crystal bot or ruby bot
<jhass> crystal, of course
<jhass> is {1, 2} valid ruby to you? :P
<ponga> ah
<jhass> to come back to that reverse thingy, I think the closed one to the ruby one is to take the ruby one and do Array(String?).new(length, nil)
<jhass> *closest, even
<ponga> ["John", "John", "Smith", "Eric", "Eric", "Eric"].each {}
<ponga> im stuck
<ponga> ;(
<ponga> maybe because i haven't slept
<jhass> >> ["John", "John", "Smith", "Eric", "Eric", "Eric"].group_by(&.itself).map {|k, v| {k, v.size} }.to_h
<DeBot> jhass: {"John" => 2, "Smith" => 1, "Eric" => 3}
<jhass> more efficient with an external hash and just += 1'ing though
<ponga> >> arr = ["John", "John", "Smith", "Eric", "Eric", "Eric"]; arr.select { |i| arr.count(i) > 1}.uniq
<DeBot> ponga: ["John", "Eric"]
<ponga> jhass: gotcha
<jhass> while that's fairly efficient on memory, it's N**2+N though
<jhass> so faster for small arrays but slower for bigger ones
<ponga> a..yeah
<ponga> doubled
<ponga> jhass: this is my best ;(...
<ponga> can't go beyond this
ponga has quit [Quit: Leaving...]
a- is now known as orliesaurus
asterite has joined #crystal-lang
asterite has quit [Ping timeout: 246 seconds]
weskinner_mac has joined #crystal-lang
weskinner_mac has quit [Quit: weskinner_mac]
shama has quit [Remote host closed the connection]
gr33n7007h has joined #crystal-lang
<gr33n7007h> jhass: ?
<jhass> yes?
<gr33n7007h> so this looks like a really cool and upcoming lang show me examples?
<gr33n7007h> whats the bot?
<jhass> >> "hi"
<DeBot> jhass: "hi"
<gr33n7007h> ah same as ruby
<gr33n7007h> cool
<gr33n7007h> >> [1,2,3,4].map {|n| n.even? }
<DeBot> gr33n7007h: [false, true, false, true]
<gr33n7007h> >> [1,2,3,4].group_by {|n| n.even? }
<DeBot> gr33n7007h: {false => [1, 3], true => [2, 4]}
<gr33n7007h> >> "string".gsub(/s/i, "888")
<DeBot> gr33n7007h: "888tring"
<gr33n7007h> mmmm..... i like it
<gr33n7007h> jhass: how to compile a simple prog
<jhass> compile & run: crystal hello_world.cr
<jhass> just compile: crystal build hello_world.cr
<gr33n7007h> 1 sec
<gr33n7007h> awesome
<gr33n7007h> so what's different from crystal to ruby?
<gr33n7007h> except from theobvoius
<jhass> a lot of stuff actually, it's not a ruby copy, just strongly ruby inspired syntax
<gr33n7007h> am liking this very much
<jhass> yeah
<gr33n7007h> jhass: could you give me an example of how to create a socket if you could?
havenwood has joined #crystal-lang
<jhass> currently a good place for examples are the specs: https://github.com/manastech/crystal/blob/master/spec/std/socket_spec.cr
<gr33n7007h> jhass: cool, how do you install/require libs?
<gr33n7007h> so with require
<jhass> there's not too much out there and dependency management is very basic still, just downloading github repos and symlinking them to the right place basically
<gr33n7007h> this looks very foooking promising
<jhass> doesn't it? ;)
<gr33n7007h> oh yeah....
<gr33n7007h> why i didn't take a look at this months ago i don't know :(
<jhass> don't worry, still the perfect time to shape the language and contribute a bit to stdlib
<jhass> everything is written in crystal itself and has pretty much rubys open class model, so very easy to just monkey patch in what's missing while working on something and turning it into a proper PR later
<gr33n7007h> or jhass man this is the shit!!!
<epitron> i know right!
<gr33n7007h> epitron: yes man
<epitron> API is a bit unstable though, watch out gr33n7007h
<gr33n7007h> gotcha @_
<epitron> i wrote a great tool, and then the core method i used disappeared :)
<gr33n7007h> shit, how?
<epitron> it wasn't cross platform enough or something
<gr33n7007h> damn
<epitron> luckily you can just copy/paste it into your script
<jhass> well, you basically had luck it was working for you :P
asterite has joined #crystal-lang
<gr33n7007h> seriously why the fuck have i not looked at this before #baffled#
<jhass> oh, good morning asterite
<epitron> asterite \o/
<asterite> good evening :)
<gr33n7007h> jhass: if it wasn't i'd make it work ! :)
<gr33n7007h> afk
<jhass> gr33n7007h: well, there simply is not cross platform way to do what it does that's anywhere near a reasonable performance
<epitron> that's so surprising1
<epitron> i thought all platforms would have a fast way of listing a dir, and telling you whether the thing was a file or a dir
<jhass> well, actually it was worse, it was filesystem specific
<epitron> (without having to call dir? on everything)
<epitron> haha
<epitron> but there must be a cross-platform way to list a directory with reasonable performance
<jhass> if you find it, I'm happy to learn about it!
<epitron> (with filenames tagged as file/dir)
<epitron> that's quite baffling
<jhass> yeah well,
<jhass> do man getpass
<epitron> haha
<jhass> " This function is obsolete. Do not use it."
<gr33n7007h> it's even got a better stack trace then ruby
<gr33n7007h> 8)
<asterite> If we find a way, we can add it. But I don't think that functionality will be a bottleneck in any program
<gr33n7007h> can you not [*1..10]?
<gr33n7007h> my mind is stamped in ruby
<jhass> 1.to(10) is better anyway :P
<gr33n7007h> Syntax error in ./foo.cr:1: unterminated array literal
<epitron> gr33n7007h: watch out for ? methods too
<epitron> they're slightly different
<gr33n7007h> in what way? epitron
<jhass> >> {1, 2}[2]
<DeBot> jhass: Error in line 3: index out of bounds for tuple {Int32, Int32}
<jhass> >> {1, 2}[2]?
<DeBot> jhass: Error in line 3: undefined method '[]?' for {Int32, Int32}
<jhass> oh :D
<jhass> >> [1, 2][2]?
<DeBot> jhass: nil
<jhass> >> [1, 2][2]
<DeBot> jhass: #{e.class}: Index out of bounds
<gr33n7007h> ok got it
<epitron> >> "hello"["hell"]?
<DeBot> epitron: "hell"
<epitron> :D
<gr33n7007h> do/end {}/ still exsist?
<gr33n7007h> do/end {}/ still exist?
<jhass> yeah
<epitron> >> begin end
<DeBot> epitron: nil
<epitron> :D
<jhass> more powerful shortform though
<epitron> the differences are subtle
<gr33n7007h> >> 1.to(10) {|n| puts n }
<DeBot> gr33n7007h: 1
<epitron> it's 95% ruby
<gr33n7007h> man i'm liking this
<jhass> >> [1,2,3].map &.+(2)
<DeBot> jhass: [3, 4, 5]
<epitron> >> 1.to(10) { |n| print n }
<DeBot> epitron: 123456789101
<epitron> haha
<epitron> it returns the 1
asterite has quit [Ping timeout: 246 seconds]
<gr33n7007h> >> 0.to(0xff) {|n| Math.sin(n) }
<DeBot> gr33n7007h: 0
<gr33n7007h> i will learn
<jhass> it's the 0 Int#to returns
<gr33n7007h> >> 0.to(0xff) &.**2
<DeBot> gr33n7007h: Syntax error in eval:3: unexpected token: .
<jhass> since you didn't do anything with the sinus ;)
<gr33n7007h> >> 0.to(0xff) &.(**2)
<DeBot> gr33n7007h: Syntax error in eval:3: unexpected token: .
<gr33n7007h> >> 0.to(0xff) &.**(2)
<DeBot> gr33n7007h: Syntax error in eval:3: unexpected token: .
<jhass> >> 0.to(0xff, &.**2)
<DeBot> jhass: Syntax error in eval:3: expecting token ')', not '2'
<jhass> >> 0.to(0xff, &.**(2))
<DeBot> jhass: 0
<jhass> >> 0.to 0xff, &.**(2)
<DeBot> jhass: 0
<gr33n7007h> >> 0.to((0xff) &.**(2))
<DeBot> gr33n7007h: Syntax error in eval:3: unterminated call
<jhass> but again just Int#to's return value
<gr33n7007h> yeah i see
<jhass> &. should be passed like an argument
<jhass> much like &: in ruby
<gr33n7007h> >> 0.to(0xff).map {|n| n**2 }
<DeBot> gr33n7007h: Error in line 3: 'Int32#to' is expected to be invoked with a block, but no block was given
<jhass> oh yeah, no Enumerator yet :/
<gr33n7007h> ah, ok#
<jhass> (1..0xff).map &.**(2)
<gr33n7007h> loving still
<jhass> >> (1..0xff).map &.**(2)
<DeBot> jhass: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 43 ...
<epitron> >> chars = %w[. - ']; 0.to(20) { |n| print chars[(Math.sin(n)+1).round] }
<DeBot> epitron: Error in line 3: no overload matches 'Array(String)#[]' with types Float64
<gr33n7007h> (0..0xff << 24).map &.even?
<epitron> chars = %w[. - ']; 0.to(20) { |n| print chars[(Math.sin(n)+1).round.to_i] }
<epitron> >> chars = %w[. - ']; 0.to(20) { |n| print chars[(Math.sin(n)+1).round.to_i] }
<DeBot> epitron: -''-..-''-...-''-..-'0
<gr33n7007h> oh shit i killed the bot lol
<jhass> nope
bcardiff has joined #crystal-lang
<epitron> >> chars = %w[. - ']; 0.to(50) { |n| print chars[(Math.sin(n)+1).round.to_i] }
<DeBot> epitron: -''-..-''-...-''-..-''-..-''-..-'''-..-''-..-''-..-0
<jhass> just forgot the >>
<gr33n7007h> >> (0..0xff << 24).map &.even?
<DeBot> gr33n7007h: [true]
<gr33n7007h> ah i get it, i think
<epitron> jhass: shouldn't round return an integer?
<jhass> epitron: nope, doesn't do in ruby either
<epitron> it does actually
<jhass> >> Math::PI.round(3)
<DeBot> jhass: 3.142
<epitron> > 1.5.round.class
<epitron> => Fixnum
<jhass> ah, mh, anyway ^ is why not
<epitron> yeah, i forgot that returning more than one type is bad in crystal
<jhass> btw, thanks, now I have a complex way to print out a separator :D
<jhass> >> chars = %w[. - ']; 0.upto(50) { |n| print chars[(Math.sin(Math::PI*n)+1).round.to_i] }
<DeBot> jhass: ---------------------------------------------------0
<gr33n7007h> >> ["a".."z"]
<DeBot> gr33n7007h: [a..z]
<gr33n7007h> >> ["a".."z"].to_a
<DeBot> gr33n7007h: [a..z]
<gr33n7007h> >> %w[/-\|].cycle(10) { |c| print c }
<DeBot> gr33n7007h: Error in line 3: undefined method 'cycle' for Array(String)
<gr33n7007h> how do get the methods of []?
<epitron> grep the source! :D
<jhass> also /topic
<gr33n7007h> kk thanks
<gr33n7007h> so there's null pointers which are false?
<gr33n7007h> ?
<jhass> yeah
<gr33n7007h> >> 0x00.class
<DeBot> gr33n7007h: Int32
<gr33n7007h> >> 0x0000.class
<DeBot> gr33n7007h: Int32
<jhass> >> if Pointer(Void).null; puts "nope"; else; "null"; end
<DeBot> jhass: "null"
<epitron> >> Void
<DeBot> epitron: Void
<epitron> >> Void.class
<DeBot> epitron: Class
<epitron> >> Void.class.class
<DeBot> epitron: Class
<epitron> >> Void.class.class.class
<DeBot> epitron: Class
<epitron> :D
asterite has joined #crystal-lang
<epitron> i wish there was a method that would apply a method to itself n times
<jhass> inject?
<epitron> i guess that works
<epitron> fixed-point kinda thing
<gr33n7007h> ?
<gr33n7007h> >> [0].pack('Q')
<DeBot> gr33n7007h: Error in line 3: undefined method 'pack' for Array(Int32)
<asterite> round returns float because for a bug number it might overflow and not fit in an int, and sometimes going to int is not needed
<asterite> bug number...
<asterite> big ...
<epitron> the word big had a bug in it
<asterite> Yes, I was thinking the same
<gr33n7007h> >> class Foo; def initialize(name = "crystal); @name = name; end; f = Foo.new
<DeBot> gr33n7007h: Syntax error in eval:6: unknown token: '#'
<gr33n7007h> >> class Foo; def initialize(name = "crystal"); @name = name; end; f = Foo.new
<DeBot> gr33n7007h: Syntax error in eval:7: expecting identifier 'end', not 'EOF'
<gr33n7007h> >> class Foo; def initialize(name); @name = name; end; f = Foo.new
<DeBot> gr33n7007h: Syntax error in eval:7: expecting identifier 'end', not 'EOF'
bcardiff has quit [Quit: Leaving.]
<asterite> one more end
<gr33n7007h> >> class Foo; def initialize(name); @name = name; end; end; f = Foo.new
<DeBot> gr33n7007h: Error in line 3: wrong number of arguments for 'Foo#initialize' (0 for 1)
<jhass> >> class Foo; def initialize(@name); end; end; Foo.new("john")
<DeBot> jhass: #<Foo:0x9331FF0 @name="john">
<gr33n7007h> >> class Foo; def initialize(name); @name = name; end; end; f = Foo.new('crystal')
<DeBot> gr33n7007h: Syntax error in eval:3: unterminated char literal
<gr33n7007h> >> class Foo; def initialize(name); @name = name; end; end; f = Foo.new('crystal'); f
<DeBot> gr33n7007h: Syntax error in eval:3: unterminated char literal
<gr33n7007h> wtf!
<asterite> ' is for char, like in java and some others
<asterite> >> 'a'.ord
<DeBot> asterite: 97
<gr33n7007h> >> class Foo; def initialize(name); @name = name; end; end; f = Foo.new('crystal')
<DeBot> gr33n7007h: Syntax error in eval:3: unterminated char literal
<gr33n7007h> >> class Foo; def initialize(@name); end; end; Foo.new('cystal')
<DeBot> gr33n7007h: Syntax error in eval:3: unterminated char literal
<gr33n7007h> >> class Foo; def initialize(@name); end; end; Foo.new("cystal")
<DeBot> gr33n7007h: #<Foo:0x819AFF0 @name="cystal">
<gr33n7007h> >> class Foo; def initialize(name); @name = name; end; end; f = Foo.new("crystal")
<DeBot> gr33n7007h: #<Foo:0x8360FF0 @name="crystal">
<epitron> asterite: the 'c' thing bugs me still
<epitron> most languages abolished that strange thing
<gr33n7007h> interpolation?
<epitron> no, using single quotes to mean a char
<epitron> >> 'c'
<DeBot> epitron: 'c'
<jhass> >> {'a', "a"}.class
<DeBot> jhass: {Char, String}
<epitron> >> 'c'.class
<DeBot> epitron: Char
<epitron> haha
<epitron> >> 'char'.class
<DeBot> epitron: Syntax error in eval:3: unterminated char literal
<gr33n7007h> ok got it
<gr33n7007h> :)
asterite has quit [Ping timeout: 246 seconds]
asterite_ has joined #crystal-lang
<jhass> asterite still needs a bouncer :P
<asterite_> epitron: but a char makes sense
<asterite_> :)
<asterite_> and are much more efficient
<epitron> i don't mind chars
<epitron> single quoted strings are nice though
<epitron> less pressing shift
<asterite_> well, you can Amway's
<asterite_> mm...
<asterite_> you can always use %(...)
<epitron> omg so much pressing shift
<epitron> :)
<asterite_> :P
<asterite_> ?a
<DeBot> asterite_: Nothing known about a.
<asterite_> ugh
<epitron> ?a was what i was expecting
<asterite_> what's "?"?
<asterite_> but ?a is ugly
<jhass> yeah, let's not do ?a
<epitron> hmmm
<epitron> \a ? :)
<jhass> \\n?
<asterite_> ¿a
<jhass> looks silly
<jhass> heh
<epitron> CHARACTER(a)
<epitron> <a>
<epitron> that's kinda cute ^_^
<epitron> [a]
<epitron> ok nevermind
<jhass> array
<epitron> yeah, i know
<epitron> i just like how it looks like a key on the keyboard
<epitron> :)
<epitron> [ENTER]
<jhass> ´a´ :D
<jhass> just to confuse everybody
asterite_ has quit [Ping timeout: 246 seconds]
havenwood has quit [Ping timeout: 256 seconds]
<gr33n7007h> :)
gr33n7007h has left #crystal-lang ["WeeChat 0.3.8"]
ponga has joined #crystal-lang
<ponga> has the style for Proc.new changed from ruby?
<ponga> Proc.new { |n| code } spits error saying wrong number of arguments
ponga has quit [Read error: Connection reset by peer]
ponga has joined #crystal-lang
asterite has joined #crystal-lang
<asterite> hi ponga
<ponga> hi
asterite has quit [Ping timeout: 246 seconds]
<jhass> ponga: yeah, always use the stabby lambda basically
<ponga> jhass: what is 'stabby' lambda
<jhass> >> -> { puts "I am" }.call
<DeBot> jhass: I am
<ponga> oh
<ponga> what is ->
<ponga> didn't see that in doc
<jhass> the stabby lambda
<ponga> >> a = -> { puts "hi" }; a.call
<DeBot> ponga: hi
<ponga> oh
<jhass> ruby has it too
<ponga> ok 'stab'
<jhass> >> lambda { "h" }
<DeBot> jhass: Error in line 3: undefined local variable or method 'lambda'
<jhass> yeah, so we don't have anything else in crystal really, so could just call it anonymous function literal or whatever
<ponga> >> a = -> do puts "hi" end; a.call
<DeBot> ponga: hi
<ponga> anonymous function sounds good
<jhass> but stabby lambda is the ruby community name :P
<ponga> dma
asterite has joined #crystal-lang
<asterite> ponga: what is alis lang? It looks similar to Esperanto in some ways
<ponga> asterite: it is influenced by Esperanto style
<ponga> its a mock-up language to support Japanese/Korean chatbot integration
<asterite> Nice
<ponga> um yeah its like ByteCode of human language
<ponga> asterite: korean/japanese sentence is converted into Alislang, then process into the bot
<ponga> compiler? maybe?
<ponga> dunno
asterite has quit [Ping timeout: 246 seconds]
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
<ponga> n
havenwood has joined #crystal-lang
<ponga> hi havenwood
<havenwood> hello
waj has joined #crystal-lang
gr33n7007h has joined #crystal-lang
havenwood has quit [Ping timeout: 264 seconds]
havenn has joined #crystal-lang
<gr33n7007h> >> a = 2 > 1 ? 100 : "100"; if a.responds_to?(:round); puts "yep"; else; puts "nope"; end
<DeBot> gr33n7007h: yep
<jhass> runtime check afaik
<jhass> but the compiler knows that the object has that method if in that branch, so it's safe to call
<gr33n7007h> to add to an array is it just .push?
<jhass> .push, or <<, just like in Ruby
<gr33n7007h> ok, thanks
<gr33n7007h> Syntax error in ./test.cr:13: for empty arrays use '[] of ElementType' ?
<gr33n7007h> doing targets = []
<jhass> yup
<jhass> needs to be targets = [] of String or whatever you want it
<gr33n7007h> howcome jhass?
<jhass> can't infer which type the array should have from pushes anywhere later in the code (yet)
<gr33n7007h> oh silly me
<gr33n7007h> so if a was pushing a struct onto the array I would do targets = [] of Struct?
<jhass> yep
<gr33n7007h> ok
<jhass> if you push multiple things, you can specify a union
<gr33n7007h> jhass how?
<jhass> targets = [] of String|Symbol
<gr33n7007h> ok got
<gr33n7007h> it
<jhass> a common union is the one with nil, Class|Nil, so it can be abbreviated with Class?
<ytti> how is crystal planning to handle language and standard libraries, will they be synchronous?
<gr33n7007h> thanks jhass
<jhass> ytti: not sure I fully understood the question, but I think so, yes
<ytti> i'll try to elaborate, take ruby and YAML parser
<ytti> it was changed, somewhat radically at one point, which caused some breakage
<ytti> and i thought, if standard libraries and language itself would live asynchronously, then you might gain feature velocity while at the same time reduce breakage
<ytti> langauge itself would have implicit standard libraries version, which it would expect
<ytti> but you could specifically in packaging specify which standard library version you are using
<jhass> mmh, I think we're still far to early to worry about such concepts yet tbh
<ytti> this way you would arbitrarily do incompatible changes to standard libraries, without fearing about breaking anything
<ytti> as you could have all the standard versions installed, and package would simply tell you which one to use
<jhass> For example you won't see Crystal supported multiple LLVM versions for quite some time
<ytti> but not incur any overhead on typical scenario, due to implicit standards version
<ytti> i think it's almost perfect situation, because later on, it'll be hard to fix
<ytti> lot of standard libraries in ruby are kind of terrible, because introducing changes there is not very practical
<gr33n7007h> how do you get a value from a struct then?
<ytti> if you could communicate in package descrpition set of standard libraries you use, new version of crystal could innovatem much more freely, without fearing breakage
<ytti> and you could run new language with older set of standard libraries
<jhass> gr33n7007h: as I understood it so far, a struct is like a regular Object still, except pass by value instead of pass by reference
<gr33n7007h> jhass: Yep, as I understand also
<jhass> ytti: don't you just trade stdlib innovation for compiler innovation? Since the compiler needs to understand old standard libraries?
<jhass> gr33n7007h: which means regular instance variables and accessors ;)
<ytti> jhass, but aren't the standard libraries high-level typically
<gr33n7007h> let me consult the docs somemore
<ytti> jhass, perhaps there needs to be another layer, low-level, which need to remain relatively static for API compatibility
<jhass> ytti: not too much, in the case of crystal at least, since it's written in itself
<ytti> jhass, and higher-level, utility libraries, whose collection version is implied by language version, but may be explicitly defined as something else
<jhass> the compiler as a program relies heavily on its stdlib
asterite has joined #crystal-lang
<jhass> ytti: have a look at the commits for 0.5.10 and 0.6.0 https://github.com/manastech/crystal/releases
<ytti> i'm looking for opposite example in crystal/tree/master/src, but yeah they are not too high level
<asterite> gr33n7007h: what are you trying to do?
<gr33n7007h> asterite: retrieve a value out of a struct would a just do getter :var1
<ytti> jhass, on example from ruby that springs to mind is 'ipaddr', it's pretty bad, but there is no reasonable way to change it, without too much breakage
<asterite> gr33n7007h: yes... doesn't work?
<jhass> ytti: anyway, my point is that I think that this would introduce way to much overhead for now that'll harm innovation at the moment
<gr33n7007h> no doesn't seem to work
<asterite> gr33n7007h: can we see your code?
ponga has quit [Quit: Leaving...]
<gr33n7007h> sure
<jhass> ytti: that is we're still below 1.0, we don't really need to worry about backwards compatibility for a while
<ytti> jhass, but once you do have to worry about, it might be hard to fix :)
<ytti> i guess it's broader discussion on the responsibilities of langauge and package manager
<jhass> Not much harder than now IMO
<gr33n7007h> just trying to learn the basics: https://gist.github.com/anonymous/30b95e21d2afa94ce29c
<ytti> i love that language has good selection of standard libraries, ruby does this fairly well
<asterite> gr33n7007h: do [] of Foo
<gr33n7007h> oh ok one sec
<ytti> andd probably the people active in development know what common use libraries are good
<asterite> the compiler won't know which of the many structs are in that array
<gr33n7007h> asterite: great that worked :)
<ytti> but if you ship them as standard library, then you're very committed to it, i'd love to have both, low commit + rich set of standard libraries
<ytti> and i think it is possible, but yeah, certainly not matter that is urgent for crystal
<asterite> ytti: the problem is that user code must rely on some common base, otherwise it's every library reinventing the wheel
<gr33n7007h> asterite: so I could do something like `targets.map &.bssid` ?
<asterite> gr33n7007h: yes, you can try
<gr33n7007h> let me try
<gr33n7007h> 1 sec
<ytti> asterite, quite and i want the stadard library to broad, i just also want it to be able to live without breakage, maybe some library which is de-facto for 5 years, suddently becomes inferior to newer alternative, which is completely API incompatible
<ytti> asterite, i'd love if language could start shipping with that library instead, without breaking
<gr33n7007h> yep, works neat
<ytti> asterite, and i think it is possible, by asynchronous standard library version and language version, but language version implies standard library version, if not explicitly statically configured
<ytti> perhapsin my gemspec i could do Gem::Specification.new do { |s| s.standard_library_version = '>=1.2.3' }
<ytti> and even though language now ships with say newer 'ipaddr' library
<ytti> my old code keeps on working, as it keeps using older 'ipaddr' library
<asterite> If your code depends on one version of the std, but your code also depends on a library that depends on another version of the std, how would that work?
<ytti> is there reason they couldn't use each their own version?
<ytti> as long as you're not serializing data between them in API dependent manner?
<ytti> isn't that problem going to surface regardless in package manager?
<ytti> if i require libA and libB >= 1.2
<ytti> but libA requires libB >=2.0
<ytti> i guess my fault then was, that i didn't specify libA version, which is compatible with my idea of libB?
<ytti> anyhow very excited about crystal, great work, i hope it keeps on gaining traction
asterite has quit [Ping timeout: 246 seconds]
<ytti> anyone happen to have idea of high performance network libraries like dpdk, netmap and pf_ring? I'm mostly C illiterate, but in need for network packet loss and jitter tester for up-to 1Gbps rates
<ytti> it seems perhaps on surface as trivial task, but if you rely on UDPSocket, your performance is going to be terrible
<ytti> i started writing one in rust, presuming i was held back by ruby, but turns out, i'm held back by linux kernel, and rust doesn't help me one bit
<ytti> and cursory look at plugging DPDK in to rust showed it to be too complex for my level of C clue
<jhass> ytti: the easiest is probably to write a binding to one of these
<jhass> writing bindings to C libraries is fairly easy in crystal
<ytti> yeah i was looking at YAML and was 'the fsck, i can understand this, surely there is some other file needed that i'm mnissing'
<ytti> but DPDK is complex in itself, even for C clued, I've understood
<ytti> maybe netmap is easier, gotta take a look one of these days
weskinner_mac has joined #crystal-lang
<gr33n7007h> just a quick question h = {} of Int32 => Int32 is that correct syntax?
<jhass> I think so, yes
<jhass> >> h = {} of Int32 => Int32
<DeBot> jhass: {}
<gr33n7007h> oh i forgot about bot only used it before aswell :)
<gr33n7007h> jhass: can that be union'd?
<jhass> it can
<gr33n7007h> thanks
<jhass> >> h = {} of Int32|Symbol => Int32|Symbol
<DeBot> jhass: {}
<jhass> >> h = {} of (Int32|Symbol => Int32|Symbol)|String => Int32
<DeBot> jhass: Syntax error in eval:3: expecting token ')', not '=>'
<jhass> okay, not that way :P
<jhass> if the Foo => Bar syntax starts to fail, use the generic one: Hash(Foo, Bar)
<gr33n7007h> ok, will do
<gr33n7007h> oh i forgot what type is Float ?
ponga has joined #crystal-lang
<jhass> >> 1.245.class
<DeBot> jhass: Float64
<ponga> >> 1.class
<DeBot> ponga: Int32
<ponga> >> "hi".class
<DeBot> ponga: String
<jhass> >> 0e24.class
<DeBot> jhass: Syntax error in eval:3: unexpected token: e24
<jhass> heh
<gr33n7007h> ah the good old class method
<ponga> >> a = -> { puts "hi"}; a.class
<DeBot> ponga: ( -> Nil)
<ponga> ?
<gr33n7007h> >> 0x00.class
<DeBot> gr33n7007h: Int32
<ponga> >> a = -> { puts "hi"}; a.class; a.call
<DeBot> ponga: hi
<ponga> >> a = -> { puts "hi"}; a.class
<DeBot> ponga: ( -> Nil)
<jhass> ponga: lambda type representation, like Foo => Bar for hash
<jhass> and puts returns nil
<jhass> >> 1e24
<DeBot> jhass: 1e+24
<jhass> ah, mh
weskinner_mac has quit [Quit: weskinner_mac]
<jhass> >> 0.1e24
<DeBot> jhass: 1e+23
<jhass> >> 0.10e24
<DeBot> jhass: 1e+23
<jhass> interesting, ruby allows 0enn ;P
<jhass> >> 0.0e24
<DeBot> jhass: 0
<ytti> >> puts "%x" % 10
<DeBot> ytti: x
<ytti> is this intentional?
<jhass> mmh
<jhass> probably not
<jhass> >> "%x" % [10]
<DeBot> jhass: "x"
<jhass> >> "%x" % nil
<DeBot> jhass: "x"
<ytti> looks intentional
<ytti> missing case for x
<jhass> ah, mh
<jhass> I wonder if we shouldn't keep the % in that case though
<ytti> we probably should raise 'malformed format string'
<jhass> mh, yeah
<jhass> pull request welcome I guess ;)
<ytti> implementing x should be pretty easy
<ytti> instead of calling to_i
<ytti> call to_i.to_s(16)
<jhass> yeah
<jhass> mmh, I wonder though..
<jhass> >> 10.to_i.class
<DeBot> jhass: Int32
<jhass> >> 10_u64.to_i.class
<DeBot> jhass: Int32
<jhass> ^ that would be not so good I guess
<ytti> ytti@ytti ~> diff formatter.cr formatter.cr.org |pastebinit 1
<ytti> for shit and giggles
<ytti> uhh
<ytti> nope
<ytti> append_arg(arg.to_i.to_s(base)) { |arg_i, arg_s| yield arg_i, arg_s }
<ytti> obviously
<jhass> uh, we're doing that %d too already, so I guess just wait until somebody trips over it :P
<ytti> heh
<ytti> but that isn't formatter problem?
<ytti> that is .to_i problem
<jhass> well, debatable
<ytti> or is to_i supposed to always return Int32?
<jhass> that's the question! ;)
<ytti> my least surprise would be to return appropriate integer
<ytti> and to_i(arg) for specific
<jhass> mmh, you want to return it a specific Int though I think, not the union of all of them
<jhass> so that's why we have to_i64 and so on already
<ytti> of course then we can debate what is appropriate, is it host dependant? or is it smallest which will fit it?
<jhass> >> "123".to_i64
<DeBot> jhass: 123
<jhass> I think it's always Int32
<ytti> that is gonna bite people
<jhass> yeah, maybe we should drop to_i and keep just to_i32 etc. :/
<jhass> *just keep
<jhass> but meh
<jhass> mmh, weird
<jhass> >> "8589934592".to_i
<DeBot> jhass: 2147483647
<jhass> >> 8589934592
<DeBot> jhass: 8589934592
<jhass> >> 8589934592.class
<DeBot> jhass: Int32
<ytti> i think it should be changed to something that returns most sensible integer, even if it is costly
<ytti> if you want performance, be explicit
<jhass> otoh one could argue that Int32 is the default integer for literals too
<jhass> >> (8589934592 + 1).class
<DeBot> jhass: Int64
<jhass> but it's a bit inconsistent atm, I agree
<jhass> haha
<jhass> >> a = 2147483648; a.class
<DeBot> jhass: Int64
<crystal-gh> [crystal] ytti opened pull request #458: support binary, octal and hex output (master...master) http://git.io/x8w8
<ytti> i need to figure out how to get llvm working, sorry guys
<ytti> but hopefully it'll give explicit idea what i'd like to be able to do
<ytti> how long does it take to compile crystal on average box?
<jhass> depends on a few factors, initial compile in release mode does take a minute or two on my i7 @ 2Ghz here
<ytti> ok good
<ytti> minutes is fine
<ytti> tens of minutes would be a problem
<jhass> yeah, no
<jhass> my IRC bot has a few kloc by now let's see the stats in release mode
<ponga> does crystal have socket class
<jhass> ponga: yup
<jhass> Parse: 00:00:00.0482750
<jhass> Type inference: 00:00:00.4211250
<jhass> Codegen (crystal): 00:00:00.1791310
<jhass> Codegen (bc+obj): 00:00:06.7517470
<jhass> Codegen (clang): 00:00:00.1464730
<jhass> that's release mode
<jhass> Parse: 00:00:00.0598570
<jhass> Type inference: 00:00:00.4404460
<jhass> Codegen (crystal): 00:00:00.2404370
<jhass> Codegen (bc+obj): 00:00:00.5519700
<jhass> Codegen (clang): 00:00:00.1611600
<jhass> that's without optimizations
<ytti> ok, that's fast
<ytti> lto of bots out there, but for my specific case (puking messages from various monitoring systems) i have requirement where one channel cannot block other channels
<jhass> ponga: specs give the best usage examples for now I'd say https://github.com/manastech/crystal/blob/master/spec/std/socket_spec.cr
<ytti> so consider you have alarm for say #company-backend-alarms and #company-frontend-alarms
<ytti> and you're getting huge flood for company-backend-alarms
<ytti> and one message to #company-frontend-alarms, and you don't want hoad of line blocking f
<ytti> you want each target to have fair share to time, not FIFO
<ytti> ended up nihhing solution, probably there are working solutions out there, but couldn't find one https://github.com/ytti/mbot/blob/master/lib/mbot/queue.rb
<ytti> other requirement that i had, which i couldn't satisfy in the few examples i read through, was ability to trigger messages without having incoming message from irc
<ytti> for say notify script, which will send you message after N passage of time
waj has quit [Quit: Leaving.]
havenwood has joined #crystal-lang
havenn has quit [Ping timeout: 246 seconds]
ponga has quit [Remote host closed the connection]
<crystal-gh> [crystal] ysbaddaden opened pull request #459: Added: Enumerable#each_slice (master...std-enumerable-each-slice) http://git.io/x8Ah
havenwood has quit [Remote host closed the connection]