Re: [chuck-users] Mixing associative with integer indexed arrays? (multiple BUGS)
Hi, Stephen!
2008/11/22 Stephen Sugden
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
<<
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
Hi, Stephen!
2008/11/22 Stephen Sugden
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 <<
>>; } //================== 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@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
2008/11/22 Stephen Sugden
Thanks kassen,
You're welcome!
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.
Well, I agree it's dubious, even if doing it in two (explicit) stages like this does work; int melodies[0]; [ 0, 2, 4, 5, 7, 9, 11, 12 ] @=> melodies; However, the reason I call it a bug is that it crashes ChucK, taking out the whole VM. Ge once said that should never happen so I "stamp" anything that does that with the "bug label". Parser errors are good, exiting the shred with a warning is fine, simply quitting is not fine, no matter how blatantly silly the stuff I type at times (I'm not especially proud of finding that spelling "class" with a capital "C" will crash...). To be sure; this was my mistake, not yours, but since it crashes like that it's still a bug.
I can certainly live with integer indexes in my script, and I'll see about adding the bug to the wiki...
You should only have to live with them temporarily; your code, aside from the way you wanted to print, was according to the language specs as I read them; you were right, ChucK was wrong. Give a shout if the Wiki gives you trouble and I'll do it but it should be there; we have a list like that for the dev's to use as a reference and for us to make sure we don't doulbe-report issues. Yours, Kas.
participants (2)
-
Kassen
-
Stephen Sugden