[chuck-users] Mixing associative with integer indexed arrays? (multiple BUGS)

Kassen signal.automatique at gmail.com
Sat Nov 22 00:17:07 EST 2008


Hi, Stephen!

2008/11/22 Stephen Sugden <glurgle at gmail.com>

> Is it possible to mix both types of array keys?



Yes... or at least it *should* be.... ;¬)


> The code I below works fine until I try to access any elements of the
> array, then I get an ArrayOutofBounds exception.


I corrected the lack of a type for "melodies".

Then I had a hard time with it, as it turns out that this;

[ 0, 2, 4, 5, 7, 9, 11, 12 ] @=> int melodies[0];

crashes ChucK. That's a bug, and it's good that we accidentally found it but
kindly try to avoid such confusion by making sure the code you send works as
you described.

Right, on to the business at hand;


> <<< scales["just"][0] >>>;
>
>
You can't print the contents of a array (which this refers to) in one swoop
like this, I fear. If you'd like to do this you'd have to loop over the
array, if they all need to be on the same line and the length of the array
is dynamic I think you'll have to join all elements together in a string and
print that.

Let's look at a version that should work properly;

//===========================
float scales[0][0][0];

[ 0, 2, 4, 5, 7, 9, 11, 12 ] @=> int melodies[];

[ [1.0, 1.0], [16.0, 15.0], [9.0, 8.0], [6.0, 5.0], [5.0, 4.0],
[4.0, 3.0], [7.0,5.0], [3.0, 2.0], [8.0,5.0], [5.0, 3.0],
 [7.0, 4.0], [15.0, 8.0], [2.0, 1.0]
] @=> scales["just"];


float et[13][2];
for(0 => int i; i <= 12; ++i){
    1.0 => et[i][0];
    Math.pow(2.0, i / 12.0) => et[i][1];
}

et @=> scales["equalTempered"];

for(int n; n< scales["just"][0].cap(); n++)
    {
   //goes out of bound for n==0 already
    <<<scales["just"][0][n]>>>;
    }
//==================

So... that's a bug, yes, and clearing out the associative indexes in favour
of ints makes it go away. Good catch!

If you'd like; add it to the Wiki here;
http://wiki.cs.princeton.edu/index.php/ChucK/Bugs/Release

Yours,
Kas.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20081122/ebc6d1fc/attachment.html>


More information about the chuck-users mailing list