ooc-dev team mailing list archive
-
ooc-dev team
-
Mailing list archive
-
Message #00273
Re: Generics
Hi there
On Wed, 2011-02-02 at 19:26 +0000, Dan Parnete wrote:
> Hello,
>
> First of all I want to congratulate you for this unbelievable project.
> It's the best thing could happens to the old C pal, a breath of fresh
> air.
Thanks a lot.
>
> I have started with the guide examples and found that Int type is not
> recognized correctly:
In fact, as your testing has shown, you want SSizeT instead of Int -
maybe some examples on the website/doc need to be adjusted
accordingly :)
It's rofl0r who decided that integer literals should be of type SSizeT
(signed, width depends of the platform) instead of Int (usually 32-bit,
at least 16 bit according to C).
Cheers,
Amos aka nddrylliog
>
> printType: func <T> (param: T) {
> if(T == Int) printf("It's an Int! and its value is %d\n", param as
> Int)
> else if(T == Char) printf("It's a char! and its value is '%c'\n",
> param as Char)
> }
> printType('c')
> // It's a char! and its value is 'c'
> printType(42)
> // nothing
>
> and
>
> Container: class <T> {
> content: T
> init: func (=content)
> get: func -> T { content }
> set: func (=content)
> }
>
> cont1 := Container<Int> new(42)
> number := cont1 get()
> "number is an %s, and its value is %d\n" printf(number class name,
> number)
> // number is an SSizeT, and its value is 42
>
> cont2 := Container<String> new("Hi, world!")
> message := cont2 get()
> "message is a %s, and its value is %s\n" printf(message class name,
> message)
> // message is a String, and its value is Hi, world!
>
> I'm using 2011-01-31 linux64 Alpaca version on Ubuntu64 10.10
>
> Thank you,
> Dan
References