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
<a5i> This project is going pretty well
<ponga> i love crystal
<a5i> same :D
<travis-ci> manastech/crystal#2237 (master - b6356e4 : Ary Borenszweig): The build was broken.
DerisiveLogic has joined #crystal-lang
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
havenwood has joined #crystal-lang
BlaXpirit has quit [Quit: Quit Konversation]
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
bcardiff has joined #crystal-lang
bcardiff has quit [Ping timeout: 250 seconds]
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
ponga has quit [Remote host closed the connection]
ismaelga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
havenwood has quit [Read error: Connection reset by peer]
havenwood has joined #crystal-lang
<a5i> Can you interop C with Crystal easily ?
<jhass> yes
<jhass> if the C is a shared library that is
<a5i> May I see an example of such ?
Wamboo has joined #crystal-lang
<Wamboo> Hi
<a5i> alhoa
<a5i> aloha*
<Wamboo> I was looking through Crystal for a bit and I was wondering how low-level it can get
<a5i> brb hot pockets
<jhass> C bindings and pointer arithmetic
<jhass> so fairly low level, no inline assembler (yet)
<jhass> also nobody tried to work without the GC yet
<Wamboo> jhass, I have en example, do you think it can be translated into Crystal?
<Wamboo> When do you think Inline asm will be implemented ?
<jhass> I don't know really
<jhass> and my C foo is weak
<jhass> I think it's possible to translate it pretty 1+1
<jhass> but it would be rather unidiomatic code
<Wamboo> If you did it?
<jhass> crystal is a strongly object oriented language after all
<Wamboo> I care not for idiomacy for now, I just want to see an equivalent example
<jhass> er, 1 to 1 I mean, it's late here
<jhass> well, writing an idiomatic equivalent would be much easier :P
<Wamboo> Is anyone else here available to try to tackle this ?
<jhass> what do you hope to see/learn? the manual memory management?
havenwood has quit []
<Wamboo> I hope to see Crystal do exactly what that C script does, so yeah
<jhass> well, crystal is a GC'ed language
<Wamboo> Yes
<jhass> so this would essentially a plain linked list I guess
<Wamboo> hmm
Wamboo has quit [Ping timeout: 246 seconds]
Wamboo has joined #crystal-lang
<jhass> http://paste.mrzyx.de/pddaya8rt ? not sure, I'm tired and not sure about the usecase of your code
<jhass> ah, allocate is append
<a5i> hm?
<Wamboo> jhass, are you updating something ?
<jhass> so more like http://paste.mrzyx.de/phl3yoxof I guess
<a5i> What's a Crystal interface?
<jhass> a5i: where did you read that?
<a5i> no where, just asking, in this case, if Crystal's has interfaces
<jhass> you could have an abstract class or a module with only abstract methods, but I don't think that's really useful, you can still duck type for a large part in crystal
knoopx has quit [Remote host closed the connection]
<a5i> jhass, so Crystal does not have interfaces like Java does or Rust's traits ?
<jhass> Wamboo: I still guess that code you posted is intended for manual memory management, since Crystal is a GC'ed language, you wouldn't want to do that in it, the GC should handle the memory management for you, that's its job
<a5i> those types of interfaces, not just abstractions
<Wamboo> jhass, I wouldnt want to, but _could_ I do it?
<jhass> yes, I think so
<jhass> pretty sure there's a way to rebind the unpatched malloc/free's
<Wamboo> Okay thanks
Wamboo has quit [Quit: Page closed]
<jhass> a5i: abstract != abstraction
<jhass> and a module with only abstract methods has the same effect as an interface in other languages
<jhass> you just don't really need it due to union types and type interference
<a5i> hmm
<a5i> I'm trying to wrap this around my head
<jhass> >> iterable = [ [1, 2], { 3, 4 } ].sample; iterable.each {|item| print item }
<DeBot> jhass: 12[1, 2]
<jhass> in that example iterable is either an Array or a Tuple
<jhass> I only know at runtime
<jhass> yet I can call each on since both implement it
<jhass> I don't need an Iterable interface
<a5i> I see
<a5i> jhass, maybe this can shed some light on to what I mean and if it can be implemented in crystal, https://gist.github.com/Ap0ph1s/9109edb3ef9559a57982
<jhass> I know zero rust, so if you could be a bit more specific...
<jhass> structs can have methods in crystal, so you'd just define an area in them
<jhass> >> struct Circle; def initialize(@x, @y, @radius); end; def area; Math::PI*@radius**2; end; end; struct Square; def initialize(@x, @y, @side); end; def area; @side**2; end; end; [Circle.new(0.0, 0.0, 1.0).area, Square.new(0.0, 0.0, 1.0).area]
<DeBot> jhass: [3.14159, 1]
<jhass> a5i: ^ like that
<a5i> uhh
<jhass> >> struct Circle; def initialize(@x, @y, @radius); end; def area; Math::PI*@radius**2; end; end; struct Square; def initialize(@x, @y, @side); end; def area; @side**2; end; end; def print_area(shape); print "Shape area: #{shape.area} "; end; print_area(Circle.new(0.0, 0.0, 1.0)); print_area(Square.new(0.0, 0.0, 1.0))
<DeBot> jhass: Shape area: 3.14159 Shape area: 1 nil
<jhass> good old duck typing
havenwood has joined #crystal-lang
<a5i> jhass, can u format that please? Ive been trying to but It won't seem to work when I then run
<a5i> been trying for a whole 9 min
<Flaise> "1 nil"? lol
<a5i> nvm jhass
<Flaise> Oh, the nil is the third element of the list, isn't it?
<crystal-gh> [crystal] asterite pushed 2 new commits to master: http://git.io/vvEUn
<crystal-gh> crystal/master 2eb756f Ary Borenszweig: Fixed: packed c structs didn't work
<crystal-gh> crystal/master 4bd2e17 Ary Borenszweig: Contributing: say to use the patched llvm if on mac
<a5i> jhass, does that solve BalXpirit's issue ^ ?
Sgeo|web has joined #crystal-lang
<travis-ci> manastech/crystal#2238 (master - 4bd2e17 : Ary Borenszweig): The build is still failing.
<a5i> jhass, 1 last question before I completely drice you insane(sorry) will I get an error if I pass something without an area method?
shama has quit [Remote host closed the connection]
shama has joined #crystal-lang
<a5i> nvm
ponga has quit [Remote host closed the connection]
donmelton has joined #crystal-lang
donmelton has quit [Client Quit]
ponga has joined #crystal-lang
shama has quit [Remote host closed the connection]
shama has joined #crystal-lang
shama has quit [Remote host closed the connection]
shama has joined #crystal-lang
shama has quit [Quit: (╯°□°)╯︵ɐɯɐɥs]
<ponga> who was making tetris game in crystal?
<ponga> ah weskinner
havenwood has quit [Ping timeout: 256 seconds]
havenwood has joined #crystal-lang
havenn has joined #crystal-lang
havenwood has quit [Ping timeout: 245 seconds]
_whitelogger has quit [Ping timeout: 272 seconds]
_whitelogger has joined #crystal-lang
havenn has quit [Ping timeout: 256 seconds]
Flaise has quit [Quit: Leaving.]
ponga has quit [Remote host closed the connection]
canhtak has joined #crystal-lang
ponga has joined #crystal-lang
sadin has joined #crystal-lang
Ven has joined #crystal-lang
Sgeo|web has left #crystal-lang [#crystal-lang]
canhtak has quit [Quit: canhtak]
canhtak has joined #crystal-lang
Excureo has quit [Read error: Connection reset by peer]
Excureo has joined #crystal-lang
BlaXpirit has joined #crystal-lang
havenwood has quit [Ping timeout: 240 seconds]
canhtak has quit [Quit: canhtak]
sadin has quit [Remote host closed the connection]
canhtak has joined #crystal-lang
canhtak has quit [Client Quit]
canhtak has joined #crystal-lang
canhtak has quit [Client Quit]
canhtak has joined #crystal-lang
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
canhtak has quit [Quit: canhtak]
canhtak has joined #crystal-lang
canhtak has quit [Client Quit]
canhtak has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
canhtak has quit [Quit: canhtak]
canhtak has joined #crystal-lang
leafybasil has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
leafybasil has quit [Remote host closed the connection]
canhtak has quit [Quit: canhtak]
leafybasil has joined #crystal-lang
canhtak has joined #crystal-lang
canhtak has quit [Client Quit]
canhtak has joined #crystal-lang
JBat has joined #crystal-lang
ponga has quit [Remote host closed the connection]
ponga has joined #crystal-lang
sadin has joined #crystal-lang
canhtak has quit [Quit: canhtak]
sadin has quit [Ping timeout: 248 seconds]
panga has joined #crystal-lang
canhtak has joined #crystal-lang
canhtak has quit [Client Quit]
Ven has joined #crystal-lang
canhtak has joined #crystal-lang
canhtak has quit [Quit: canhtak]
DerisiveLogic is now known as danecandor
BlaXpirit has quit [Quit: Quit Konversation]
sandelius has joined #crystal-lang
danecandor has quit [Ping timeout: 256 seconds]
sadin has joined #crystal-lang
canhtak has joined #crystal-lang
sadin has quit [Ping timeout: 246 seconds]
<a5i> ping shadeslayer
<shadeslayer> hi
<shadeslayer> whats up?
<a5i> Hi, what is dataminer ?
<shadeslayer> a5i: it's a thing I was writing for mining spanish election data
<shadeslayer> from 2011
<a5i> ooh
<a5i> cool
<shadeslayer> as part of a hackathon, it's written in Ruby, but then I started converting it to Crystal, but then didn't find the time to finish it
<shadeslayer> a5i: http://people.ubuntu.com/~rohangarg/test.json < what the output looks like ( warning, it's huge )
<a5i> whoa
<shadeslayer> thats just for one province though (Andalucia)
<shadeslayer> and I don't have the new data to plug into the project yet
ponga has quit [Quit: Connection closed for inactivity]
<crystal-gh> [crystal] Exilor opened pull request #542: Removed a non-breaking space (master...patch-1) http://git.io/vvzrA
canhtak has quit [Quit: canhtak]
canhtak has joined #crystal-lang
canhtak has quit [Quit: canhtak]
canhtak has joined #crystal-lang
ismaelga has joined #crystal-lang
sadin has joined #crystal-lang
canhtak has quit [Quit: canhtak]
sandelius has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
colorados has joined #crystal-lang
canhtak has joined #crystal-lang
sandelius has joined #crystal-lang
canhtak has quit [Quit: canhtak]
ismaelga has quit [Ping timeout: 256 seconds]
ismael__ has joined #crystal-lang
BlaXpirit has joined #crystal-lang
ismael__ has quit [Ping timeout: 248 seconds]
<BlaXpirit> how do i know
<a5i> We were talking about how packed C structs were not working well in crystal, that says its fixed :P
<a5i> I'll ask asterite for more clarity
<jhass> a5i: no, _passing_, not _packing_
<a5i> Oh
<a5i> Well that;s confusing, nvm :(
ismaelga has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Flaise has joined #crystal-lang
canhtak has joined #crystal-lang
Ven has joined #crystal-lang
Ven has quit [Client Quit]
ismaelga has quit [Ping timeout: 248 seconds]
ismaelga has joined #crystal-lang
sandelius has quit [Quit: Textual IRC Client: www.textualapp.com]
bcardiff has joined #crystal-lang
asterite has joined #crystal-lang
<asterite> jhass: o/
<jhass> he
<jhass> y
<jhass> asterite: I have a weird thought
<asterite> I have a regular question :-(
<asterite> Tell me
<jhass> you know, there's one part in Ruby that is like a big hole in it's dynamic nature
<jhass> you can't affect truthy/falsy
<asterite> Oh, initially we had to_b so you could control it
<asterite> but I think it's best if you can't affect it
<jhass> and now the weird thought: what if we let the compiler call to_bool in conditions (if, unless, while, until) if it is defined?
<jhass> mmh
<asterite> Imagine you have `if foo` in your code, and you know that this will be true if foo is not nil nor false
<asterite> but someone defines to_b on it and crashes your code
<asterite> Well, that can happen with any method, actually, but here it's an implicit method, so it's harder to realize that
<jhass> eh well, I can already redefine for example ! to always return true
<jhass> or false
<asterite> I think we will make ! also a non definable method
<jhass> mmh
<asterite> For example, what's String#to_b?
<asterite> Is it when it's length is zero, or also when all the chars are whitespace?
<jhass> point is Ruby has a shitload of possibilities already to break code in subtle ways
<jhass> no, String wouldn't have to_b
<asterite> Why not?
<jhass> the 99% case would be to have non
<jhass> and have the current rules, false and nil are treated falsey, everything else truthy
<Flaise> There's a to_b for strings and lists and maps in Python because when those are empty, they are falsy.
<jhass> I'm more thinking of giving Proxy/Delegator objects the possibility to control it
<jhass> rare exceptions like that
<asterite> Well, you can create an RFC so we can have more opinions, thoughts :)
<asterite> My personal opinion is no, I don't know what waj and others think about it
<jhass> yeah, I said it's a weird thought, so I'm only 60% sure I'd like it :D
<jhass> I can understand why it's not there in Ruby, having a method lookup in every condition would be insane
<jhass> but in crystal that lookup would be compile time only
<jhass> and affect runtime only in the few cases it actually happens
<asterite> Yes. In the beginning we had that method but later removed it, can't remember the reason. It's probably that "if foo" implies foo is not nil, but what happens if you define to_b on Nil?
<jhass> mmh, right
<jhass> would need to disallow cases like that
<asterite> jhass: the question I had I already asked at the #rust channel, but just in case. I ported this code from Rust to Crystal: https://github.com/rust-lang/rust/blob/master/src/librustc_trans/trans/cabi_x86_64.rs . I'll commit it later, but I'm not sure what to do with the copyright. I need to leave that same copyright message they have at the top of the file, and also mention that I ported it from there?
<asterite> Our licences are both Apache 2.0 so I guess they are compatible
<jhass> It's new code, hardly patentable
<jhass> so I'd say etiquette is enough, I usually leave a # Inspired by ...
<asterite> So the copyright only applies if it's a direct copy-paste with just a few modifications?
<jhass> I'm really no lawyer, so take everything I say with a grain of salt, but that's my understanding
<asterite> (there's also the thing that this algorithm is written in words in a public PDF)
<jhass> yeah, just was going to say
<jhass> there's no original algorithm in it, thus nothing patentable
<asterite> So it's just "I found it easier to port code than words"
<jhass> yeah, it's still new code and your own creation
<jhass> let's make this over music, that's easier
<jhass> have you been to soundcloud? all the people that upload mixes of popular music?
<asterite> No, but I know that music
<jhass> not even half of them pay fees, soundcloud pays a few to not bother with legal claims mostly, but not for everything
<asterite> (in any case, if I leave the copyright notice it can't hurt, right?)
<jhass> that's okay because authoring the mix is a significant amount of work
<jhass> and thus the result qualifies as a new piece
<jhass> and I'd say we can apply similar metrics here, porting it is a significant amount of work and requires skill (knowledge of the target codebase in this case) and originality (adapting it to the target)
<jhass> thus it's a new piece
<jhass> it's actually similar to the 2048 sample, where I left the inspired note
<jhass> it's a new implementation, I just took the idea, which is unlikely to be copyrighted
<jhass> at least in my jurisdiction
<asterite> Good, so I'll leave the "Based on ..." note :)
<jhass> yup, that should be fine ;)
<jhass> and I mean if somebody is not okay with it, they'll usually leave a note and we can adapt, that's totally okay with the large majority of people
<asterite> Yes, that's what I thought, I would have no problem if I had to put a copyright notice there
<asterite> By the way, after I run 2048 on a mac... the "k" letter doesn't work anymore
<asterite> (yes, you read that well)
<jhass> uhm...
<jhass> I have no mac to test!
<jhass> :P
<asterite> Hehehe, don't worry, it's a minor issue
<jhass> try running the reset command
<jhass> (luckily that works without k!)
<asterite> Nope, reset and still without a k
* jhass shrugs
<asterite> But don't worry, I'm more interested right now in getting right the x86_64 abi so we can use more c libs :)
<jhass> \o/
<jhass> but I guess we'll need i636 too, no?
<jhass> or x86 how rust calls it
<asterite> I think it's called x86 there, but the algorithm is easier
<a5i> Can we index hashes by the values of the keys ?
<a5i> if maybe you don't know the hash key ?
<a5i> Ill ask Ruby
<jhass> a5i: please rephrase if you do so :P
donmelton has joined #crystal-lang
donmelton has quit [Client Quit]
DerisiveLogic has joined #crystal-lang
sadin has quit [Remote host closed the connection]
DerisiveLogic has quit [Ping timeout: 246 seconds]
canhtak has quit [Quit: canhtak]
havenwood has joined #crystal-lang
asterite has quit [Quit: Page closed]
sadin has joined #crystal-lang
havenwood has quit [Ping timeout: 245 seconds]
<a5i> hmm
shama has joined #crystal-lang
panga has quit [Remote host closed the connection]
havenwood has joined #crystal-lang
jua_ has joined #crystal-lang
DerisiveLogic has joined #crystal-lang
waterlink has joined #crystal-lang
<waterlink> hi all, how do I define a property with type?
<waterlink> >> class X; property id : Int; end
<DeBot> waterlink: Syntax error in eval:3: unexpected token: :
<waterlink> >> class X; property id of Int; end
<DeBot> waterlink: Syntax error in expanded macro: getter:4: unexpected token: ( (expected ',' or ')')
<a5i> uhhh
<waterlink> >> class X; property id(Int); end
<DeBot> waterlink: Syntax error in expanded macro: getter:4: unexpected token: Int
<a5i> >> struct X; @id : Int32; end;
<DeBot> a5i: Syntax error in eval:3: unexpected token: :
<a5i> Not sure, maybe jhass knows
<waterlink> it should be possible, because setter macro code checks for just name, or for DeclareVar, which has var and type..
<a5i> I usually let Crystal infer my type
<jhass> yeah, I'm actually wondering the same for some time
<jhass> >> class Foo; property foo :: Int32 end;
<DeBot> jhass: Sorry, that took too long.
<jhass> >> class Foo; property foo :: Int32 end;
<DeBot> jhass: nil
BlaXpirit_ has joined #crystal-lang
<jhass> >> class Foo; property foo :: Int32 end; Foo.new.foo = "foo"
<DeBot> jhass: Error in line 3: no overload matches 'Foo#foo=' with types String
<jhass> \o/
<a5i> >> True.is_a?(Bool)
<DeBot> a5i: Error in line 3: undefined constant True
<a5i> mk
<a5i> jw
<jhass> >> true.class
<DeBot> jhass: Bool
<a5i> ik i was just wondering if Crystla has uppercase bools
<a5i> which sounds silly now
<jhass> >> True = true; False = false; # now it has :P
<DeBot> jhass: nil
<jhass> waterlink: noticed ^ ?
BlaXpirit has quit [Ping timeout: 256 seconds]
BlaXpirit_ has quit [Client Quit]
BlaXpirit has joined #crystal-lang
<waterlink> Yeah, thanks @jhass!
<a5i> orl
<a5i> y
<jhass> I realized that foo : Int32 is a type restriction, not a variable declaration, had been wondering that in the past too :D
<a5i> >> x = {"apple" => "food"}; x[0]
<DeBot> a5i: MissingKey: Missing hash value: 0
<a5i> >> x = {"apple" => "food"}; x.value[0]
<DeBot> a5i: Error in line 3: undefined method 'value' for Hash(String, String) (did you mean 'values'?)
<a5i> >> x = {"apple" => "food"}; x.values[0]
<DeBot> a5i: "food"
<a5i> mk
<a5i> >> x = {"apple" => "food"}; x.key[x.values[0]]
<DeBot> a5i: Error in line 3: undefined method 'key' for Hash(String, String) (did you mean 'keys'?)
<a5i> >> x = {"apple" => "food"}; x.keys[x.values[0]]
<DeBot> a5i: Error in line 3: no overload matches 'Array(String)#[]' with types String
waterlink has quit [Quit: Leaving.]
<a5i> >> x = {"apple" => "food"}; x.keys(x.values[0])
<DeBot> a5i: Error in line 3: wrong number of arguments for 'Hash(String, String)#keys' (1 for 0)
<a5i> >> x = {"apple" => "food"}; x.key("food")
<DeBot> a5i: Error in line 3: undefined method 'key' for Hash(String, String)
<a5i> jhass, Is that method you told me in Ruby in Crystal?
<jhass> apparently not
<jhass> somebody probably should add it
<a5i> any other equivalent?
<jhass> well, it's still an anti-pattern that you need to lookup by value
<jhass> but Enumerable#find should do just fine
canhtak has joined #crystal-lang
<a5i> uhhh
<a5i> Hash.find ?
waterlink has joined #crystal-lang
<a5i> no, im not quite ssure
<waterlink> >> x={"apple"=>"food"}; x.keys[0]
<DeBot> waterlink: "apple"
<waterlink> a5i: ^ - is that what you wanted?
<a5i> waterlink: No, I need to search the hash by value, not key or numeric type
<waterlink> >> x={"apple" => "food"}; x.find { |k, v| v == "food" }
<DeBot> waterlink: Error in line 3: undefined method 'find' for Hash(String, String)
<waterlink> >> x={"apple" => "food"}; x.first { |k, v| v == "food"  }
<DeBot> waterlink: Syntax error in eval:3: unexpected token:  
<jhass> uh, we don't?
Regexident has joined #crystal-lang
<jhass> >> {}.is_a? Enumerable
<DeBot> jhass: Syntax error in eval:3: for empty hashes use '{} of KeyType => ValueType'
<jhass> >> {a: :b}.is_a? Enumerable
<DeBot> jhass: false
<jhass> meh
<waterlink> heh )
<waterlink> probably because Enumerable relies on #each
<waterlink> but each in Hash is a bit special
<jhass> I guess we would need autosplatting on yield, yeah
<waterlink> a5i: is it a solution for you to build inverted Hash ?
<jhass> making the Enumerable(T) Tuple(K, V) shouldn't be the issue
<jhass> that Enumerable expects a single param from .each is it rather
<waterlink> >> x = { "apple" => "food" }; y = {} of String => String; x.each { |k, v| y[v] ||= k }; y["food"]
<DeBot> waterlink: "apple"
<a5i> Ima think about it
<waterlink> but be careful with this approach, be aware of duplicated values
ismaelga has quit [Remote host closed the connection]
<waterlink> Is it possible to write a spec that will check that certain thing will fail to compile ?
<jhass> >> {a: :b}.invert
<DeBot> jhass: Error in line 3: undefined method 'invert' for Hash(Symbol, Symbol)
<jhass> so much to do ...
<waterlink> expect_not_compiles do …. end
<waterlink> or something
asterite has joined #crystal-lang
<waterlink> or for that you need to include compiler in your specs and do it yourself ?
<asterite> >> {"apple" => "food"}.to_a.find { |x| x[1] == "food" }
<DeBot> asterite: {"apple", "food"}
<waterlink> ah, to_a
<waterlink> that works
<asterite> A bit annoying because it creates an extra array, but when we'll have iterators you
<asterite> you'll be able to do each.find { ... }
<asterite> There's also a possibility of making a Hash be an Enumerable of tuples... I don't know how Enumerable works when yielding many values
<asterite> (in Ruby)
<asterite> It's too magical for my taste :)
<jhass> yield 1, 2 is implicit for yield [1, 2]
<jhass> and blocks autosplat, so [[1, 2], [3, 4]].each do |x, y| works
<jhass> try some_hash.each {|x| p x } in Ruby
colorados has quit [Ping timeout: 250 seconds]
<asterite> I think I use that in Ruby, but maybe it's bug prone, don't know. Would be better to do ".each do |(x, y)|" or something
<jhass> you can actually do that in Ruby
<jhass> and I think I opened an issue about advanced destructing assignment already :P
<a5i> >> $s = 6; s
<DeBot> a5i: Error in line 3: undefined local variable or method 's'
<a5i> isnt that a global variable ??
<jhass> yeah
<jhass> the $ is part of the name
<jhass> $s != s
<a5i> oh yeah
asterite has quit [Quit: Page closed]
colorados has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]
<Flaise> >> nil
<DeBot> Flaise: nil
<Flaise> My first Crystal program is a success.
<jhass> \o/
<waterlink> >>
<waterlink> >>
<waterlink> >>0
<DeBot> waterlink: 0
<jhass> >> ​  = "hey"; ​ .upcase
<DeBot> jhass: "HEY"
havenn has joined #crystal-lang
havenwood has quit [Ping timeout: 246 seconds]
leafybas_ has joined #crystal-lang
leafybas_ has quit [Remote host closed the connection]
Regexident has quit [Read error: Connection reset by peer]
leafybasil has quit [Ping timeout: 255 seconds]
havenn is now known as havenwood
asterite has joined #crystal-lang
<asterite> waterlink: you are doing some crazy stuff with crystal, like mocks.cr
<waterlink> asterite: yeah, I know :)
<waterlink> btw, why this doesn't work:
<waterlink> >> struct Null < Int32; end
<DeBot> waterlink: Error in line 3: Int32 is not a class, it's a struct
<waterlink> whereas this works, but creates abstract struct:
<waterlink> >> struct Null < Int; end
<DeBot> waterlink: nil
<asterite> Strange. The first one is a bu
<asterite> g
<asterite> In any case, if you extend from Int32 how do you instantiate it?
<waterlink> ah yes
<waterlink> What am I trying to make is Null Object pattern for Int
<asterite> So any method you call on Null gives Null?
<waterlink> Probably I'm better to derive from abstract Int and define all abstract methods, so that behaviour is okaish
<waterlink> Not exactly
<waterlink> it will give you some sane default
<waterlink> so How does one include Comparable in crystal ?
<asterite> Hm, that code doesn't crash on me
<asterite> You do include Comparable(TypeAgainstYouWantToCompare)
<asterite> you can include it many times to compare against many types
asterite has quit [Quit: Page closed]
jua__ has joined #crystal-lang
<waterlink> Got it
canhtak has quit [Quit: canhtak]
jua_ has quit [Ping timeout: 264 seconds]
<Flaise> Hey, does/will Crystal have a way to minimize overhead for stuff like representing numbers with units in a type-safe way? For example, in C# there's a TimeSpan type but that bundles in type information if I understand correctly. And Scala has implicits but those are obfuscatory and not type safe.
sadin has quit [Remote host closed the connection]
waterlink has quit [Quit: Leaving.]
sadin has joined #crystal-lang
JBat has quit [Quit: Computer has gone to sleep.]
leafybasil has joined #crystal-lang
<a5i> When you require a file, everything in that file is available in the one you required it from? (variables included) ?
<a5i> and anonymous functions?
<jhass> mh, I think toplevel locals are not shared, top level instance variables are forbidden in Crystal, toplevel methods are shared and of course globals and constants are shared
<a5i> I see
asterite has joined #crystal-lang
<asterite> Flaise: yes to your question. The answer is structs. In fact our Time and TimeSpan are based on those of Mono, which wrap an Int64, so their representation is pretty efficient
<asterite> a5i: you can also have file-level defs, with `private def`... I guess we could do the same for types
sadin has quit [Remote host closed the connection]
asterite has quit [Quit: Page closed]
canhtak has joined #crystal-lang
sadin has joined #crystal-lang
waterlink has joined #crystal-lang
ismaelga has joined #crystal-lang
ismaelga has quit [Ping timeout: 240 seconds]
ismaelga has joined #crystal-lang
<Flaise> Cool. I can't think of a use case for a file-level typedef that would be more helpful than the convenience of a renamed import, though.
<Flaise> Oh, you were talking to someone else. lol
flan3002 has joined #crystal-lang
canhtak has quit [Quit: canhtak]
jua__ has quit [Quit: Vision[0.9.7-H-20140108]: i've been blurred!]
canhtak has joined #crystal-lang
havenwood has quit [Remote host closed the connection]
shama_ has joined #crystal-lang
shama has quit [Ping timeout: 245 seconds]
<Flaise> So let me make sure I understand this: In Crystal, passing around a struct composed of primitives is exactly the same overhead as passing around the primitives manually as function arguments?
<BlaXpirit> probably, i dunno
<jhass> asterite hides all kind of useful information behind innocent blog headlines ;P
<Flaise> Yes, reading those headlines is kind of like reading a documentation like this: `class Vector /** This class works. */` ..... -____-
<Flaise> So I'm looking at the part that says %Point = type { i32, i32 }
<Flaise> I guess the answer is yes?
<jhass> I guess, I'm not 100% sure myself
<jhass> or rather I don't know how/if alignment is relevant in a method call when passing them as individual params
<waterlink> Ahh, Bug: trying to upcast Hash(String+, (String+ | Int)) <- Hash(String+, Int32)
<Flaise> If it is the case then that's awesome because as far as I'm aware, that's the single biggest issue with performance in memory-managed languages used in production today.
<jhass> String+ doesn't sound good waterlink :P
<jhass> subclassing String, eh?
<waterlink> >> class String; class Null < self; end; end
<DeBot> waterlink: Syntax error in eval:3: expecting token 'CONST', not 'self'
<waterlink> class String; class Null < String; end; end
<waterlink> >> class String; class Null < String; end; end
<DeBot> waterlink: nil
<waterlink> >> class String; class Null < String; end; end; String
<DeBot> waterlink: String
<waterlink> >> class String; class Null < String; end; end; String|String::Null
<DeBot> waterlink: Error in line 3: undefined method '|' for String:Class
<jhass> [] of String|String::Null
<jhass> ([] of String|String::Null).class
<jhass> that's my usual demo trick :P
<waterlink> >> class String; class Null < String; end; end; ([] of String).class
<DeBot> waterlink: Array(String+)
<Flaise> >> ([] of String|String::Null).class
<DeBot> Flaise: Error in line 3: undefined constant String::Null
<waterlink> And String::Null has some good defaults inside, aka null object
<jhass> I wonder how you could get with ducktyping & unions
<jhass> *how far
<Flaise> >> String.class
<DeBot> Flaise: Class
<Flaise> lol
<Flaise> As though I didn't already know it were a class.
<Flaise> >> String.class +""
<DeBot> Flaise: Error wrong number of arguments for 'String#+' (0 for 1)
<Flaise> >> String.class.to_str()
<DeBot> Flaise: Error in line 3: undefined method 'to_str' for Class (did you mean 'to_s'?)
<Flaise> >> String.class.to_s()
<DeBot> Flaise: "Class"
BlaXpirit has quit [Quit: Quit Konversation]
canhtak has quit [Quit: canhtak]
sadin has quit [Remote host closed the connection]
ssvb has joined #crystal-lang
<waterlink> jhass: pretty much if you have points in the system where these unions are narrowed down always to 1 or 2 types )
<waterlink> and if it is impossible, then it is fine to fail, because it is basically a violated contract
shama_ has quit [Quit: (╯°□°)╯︵ɐɯɐɥs]
<waterlink> Hmm
<waterlink> I can't understand how can my code refer the same integer from different places, they are passed by value, aren't they?
<waterlink> and when I do some_hash["hello_world"] = 4, shouldn't it discard old value, and just write a new one ?
<waterlink> instead of mutating the Int that is already there..
barosl__ has joined #crystal-lang
<waterlink> Ahh
<waterlink> Silly me
<waterlink> Not an integer was referred from 2 places
<waterlink> But the whole Hash :)
<waterlink> Super encapsulation level
<waterlink> Just give somebody all your data and then mutate it
<waterlink> encapsulation :troll_level
ryanf_ has joined #crystal-lang
barosl_ has quit [Ping timeout: 250 seconds]
ryanf has quit [Ping timeout: 248 seconds]
DerisiveLogic has quit [Ping timeout: 264 seconds]