Crystal

Ary Borenszweig ary at esperanto.org.ar
Sun Feb 17 12:22:50 PST 2013


On 2/17/13 4:09 PM, Jacob Carlborg wrote:
> On 2013-02-17 17:34, Ary Borenszweig wrote:
>
>> As I replied to Denis, you can specify type restrictions in functions
>> and methods.
>>
>> def foo(x : Int)
>>    1
>> end
>>
>> foo "Hello" # Gives a compile error
>>
>> It works similar to overloaded templates: you don't specify the type of
>> the function, but which types you can give to it. In the case of Int, of
>> course it will always just accept an Int. But you can specify for example
>>
>> def foo(x : Enumerable)
>> end
>
> Yeah, I saw there's explicit static typing.
>
>> And there's a special restriction, self, that will only match for the
>> owner of the method. This is used for example in the Comparable module:
>>
>> https://github.com/manastech/crystal/blob/master/std/comparable.cr
>
> So in that case "self" would evaluate, at compile time, to whatever
> Comparable is mixed in to?

Yes.

>
>> I thought it was supported but it's not. It would be very easy to
>> support it, but it would execute at run time, as if you had put it
>> before the class declaration.
>
> That code will be executed as soon as the file has been loaded using
> "require"?

Since it's not yet implemented, it could be like that, or it can be that 
it is evaluated when you execute the program (but not at compile time).


More information about the Digitalmars-d-announce mailing list