[chuck-users] Ragged object array

Dana Batali dana.batali at gmail.com
Fri Jan 7 11:45:31 EST 2022


Fellow ChucK users:  can anyone comment on the possibility of achieving a
ragged object array in ChucK?  By ragged array, I mean an array of arrays
of Objects as opposed to a 2D array.

The docs state that an array is an Object, so it's within the realm of
possible, by my current guess is that it's not possible to cast an Object
to an array so that I can invoke, eg, it's size method.

Any comments appreciated!
Thanks in advance, Dana

Here's some not-quite working code:

// this part works.
Object @ meta[]; // an array of arrays of objects (ragged)
for(int i;i<10;i++)
{
    Object subarray[0];
    meta << subarray;
}

// here's the problem:

// Object  has no method size() (compile-time failure)
// <<< "element[2] size: " , meta[2].size() >>>;

// so the solution must involve a cast operation
// but this produces a syntax error
(meta[2] $ Object[]) @=> Object a[];
<<< a.size() >>>;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20220107/be3c10bd/attachment.html>


More information about the chuck-users mailing list