[chuck-users] Doing something to all members of a class?

Scott Wheeler wheeler at kde.org
Tue Mar 13 21:49:20 EDT 2007

David Powers wrote:
> 2. Give the class a static array property

This is what I first tried in the implementation that I sent, but I 
quickly ran into a (documented, 
http://wiki.cs.princeton.edu/index.php/ChucK/Bugs/Known) ChucK bug.  
Static objects are not properly initialized, which includes arrays.  And 
unlike other objects, it seems that you can't assign an array to an 
Object.  (i.e. "new int[20] @=> Object foo;" doesn't work)  The only way 
I saw to work around this was creating another class as an array handle 
and using that by reference.  So:

class Foo
    class ArrayHandle
        int values[20];

    static ArrayHandle @ handle;

    if(handle == null)
        new ArrayHandle @=> handle;

    // ...

Then all access to the value array has to be done via 
handle.values[...].  But then that was almost as much code as writing 
the list.  :-)


More information about the chuck-users mailing list