[chuck-users] chuck-users Digest, Vol 17, Issue 11

Scott Wheeler wheeler at kde.org
Mon Dec 18 20:45:04 EST 2006

kijjasak triyanond wrote:
> Oh.. yes yes & yes!
> this is the OOP idea i'm not familiar with.
> so this is how it works.. wow.
> new item.. and new @ variable.. wow.
> i was always trying to do something like this with other stuffs.
> but i didn't use @ for a new pointer variable..
> i had no idea hahah.. thanks Scott. this is so clear.
> and it gives me a lot of new ideas & a breakthrough for more things i 
> can do in ChucK!

Actually, if it's being used for instructional purposes, I feel like I 
should post the cleaned up version:

class IntStack
    class Item
        0 => int value;
        Item @ below;

    Item bottom @=> Item top;

    fun void push(int value)
        Item item;
        value => item.value;
        top @=> item.below;
        item @=> top;

    fun int pop()
        top.value => int value;

            top.below @=> top;

        return value;

    fun int isEmpty()
        return top == bottom;

This is one of the syntactic quirks of ChucK -- the following are 

Item foo;
new Item @=> Item @ foo;

...which I feel like is an unnecessary ambiguity.  The syntax roughly 
mimics C++ in both cases, but in C++ those would be quite different.


More information about the chuck-users mailing list