<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
<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
<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?
<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