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

Andrew C. Smith acsmith at willamette.edu
Tue Sep 15 09:54:54 EDT 2009


Kas,

Thanks, that works perfectly. How does setting the length at
initialization make logical sense? I mean that in a curious, not a
critical way. I'm just not sure what the nature of the issue is,
because it seems like declaring a single primitive is the same as
declaring 128 of them, right? (clearly wrong).

And anyway, who needs examples when you have a list? Think of all the
people we would never meet (figuratively) in a world of perfect
documentation.

David: I like what you're doing there, and I've done something like
that in the past. My goal for this project is to have a global static
scale so that I can have one shred repeating some figure, then have
its intonation changed by another shred. Right now it's using FileIO
to read in tunings from outside, so that I can add new tuning options
without re-compiling the class (since you can only spork a public
class once per VM load). Still pretty theoretical, but I needed
something better and more flexible than this:
http://www.andrewchristophersmith.com/machines/chuck/scalar.ck

2009/9/15 Kassen <signal.automatique at gmail.com>:
> Andrew;
>
>>
>> [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.
>
> yours,
> Kas.
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>


More information about the chuck-users mailing list