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

Stephen Sugden glurgle at gmail.com
Sat Nov 22 00:39:08 EST 2008


Thanks kassen,

sorry about leaving the melodies variable in there, I will definitely do a
better review of any code I send int the future.

I thought I should mention that this line:

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

Crashing chuck doesn't seem like a bug to me, because I had created melodies
as a two dimensional array with both lengths defined (melodies[10][88]) and
that's why it worked for me. Whereas if melodies isn't created yet, assigned
something to index 0 shouldn't necessarily work.

I can certainly live with integer indexes in my script, and I'll see about
adding the bug to the wiki...

-Stephen


On Fri, Nov 21, 2008 at 9:17 PM, Kassen <signal.automatique at gmail.com>wrote:

>
> 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.
>
> _______________________________________________
> 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/20081121/7cf39566/attachment.htm>


More information about the chuck-users mailing list