[chuck-users] Static data problem (arrays, floats)

Kassen signal.automatique at gmail.com
Tue Sep 15 08:33:35 EDT 2009


> [Rational_io.ck]:line(16): cannot declare static non-primitive objects
> (yet)...
> [Rational_io.ck]:line(16): ...(hint: declare as ref (@) & initialize
> outside for now)
Yeah, that's a bit tricky. Have a look at this;
class war
    //define array
    static float  foo[];

    //fill it and return it
    fun static float[] bar()
        for (int n; n< foo.cap(); n++) n => foo[n];

        return foo;

 //initiate the array outside of the class
 new float[10] @=> war.foo;

// test, should print "3.0000"
<<< war.bar()[3] >>>;

With arrays of primitives the syntax somehow becomes a bit differently from
the more regular

static Event @ my_event;

...and we have to define them as normal except not set the length, the
length will be set at initiation, which seems somewhat logical considering
the nature of the issue but it took me a while to figure it out as well.

We might consider having some examples in the /examples/ dir to illustrate
this kind of thing as it leads to a lot of questions.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20090915/b194be66/attachment.htm>

More information about the chuck-users mailing list