[chuck-users] Ragged object array

Dana Batali dana.batali at gmail.com
Fri Jan 7 13:23:41 EST 2022


One more note on David's suggestion.
I didn't really want to keep separately named subarrays around (here, a and
b) and found the following variation to work.

int meta[2][0];
[0, 1, 2, 3] @=> int b[];
[10, 11, 12, 13, 14, 15] @=> int c[];
b @=> meta[0];
c @=> meta[1];

for(int j; j< meta.size(); j++)
{
    for (int i; i< meta[j].size(); i++)
        <<< " meta[", j, ",", i, "] ==", meta[j][i] >>>;
}

Regards, Dana

On Fri, Jan 7, 2022 at 10:14 AM Dana Batali <dana.batali at gmail.com> wrote:

> Hey David, (mind blown).
>
> Very interesting and useful trick!  My c++ brain didn't allow for this
> possibility.   Esthetically the misrepresentation of the array "shape"
> bothered me.   I found that I could be less bothered by changing one line
> and it still works!
>
> int meta[2][0];
>
> Thanks for playing!
> Dana
>
>
> On Fri, Jan 7, 2022 at 10:06 AM David Loberg Code <d.loberg.code at wmich.edu>
> wrote:
>
>> Dana,
>>
>> I realize that this example is a 2D array, but does this workaround
>> accomplish what you want?
>>
>>
>>
>> int meta[2][2];
>>
>>
>> [0, 1, 2, 3] @=> int b[];
>>
>> [10, 11, 12, 13, 14, 15] @=> int c[];
>>
>>
>> b @=> meta[0];
>>
>> c @=> meta[1];
>>
>>
>> for (int i; i< b.size(); i++)
>>
>> { <<< " b["+i+"] ==", meta[0][i] >>>; }
>>
>>
>> for (int i; i< c.size(); i++)
>>
>> { <<< "c["+i+"] ==", meta[1][i] >>>; }
>>
>>
>> Santé,
>> davd
>>
>> -----------------
>>
>> David Loberg Code
>>
>> School of Music
>>
>> Western Michigan
>>
>> code at wmich.edu
>>
>> *any pronouns*
>>
>> ------------------------------
>>
>>
>> _______________________________________________
>> chuck-users mailing list
>> chuck-users at lists.cs.princeton.edu
>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20220107/1ac39087/attachment.html>


More information about the chuck-users mailing list