Hi list, I have a slight issue. I'd like to have a array in which every object itself is a array. Particularly I'd like to have one of 8 locations each of which holds a array of length 32. I tried this; int[32] memory[8]; And the miniaudicle immediately complains. I know the manual doesn't explicidly say arrays can hold arrays but it didn't explicidly say functions can return arrays either so I thought I'd try anyway (and frankly I feel this should simply be possible). Theoretically speaking I could get by with a 2d array but I'd realy like to be able to go; if(some event dealing with storing patern memories) { patern @=> memory[4]; } if(some event dealing with recaling patern memories) { memory[3] @=> patern; } How to go about this? In the interest of staying readable and compact I'd much prefer no to have to loop over a 2d arrays row in order to copie values one by one. Should I use the asociative array features? Am I missing some syntax bit? Are there reasons not to store arrays in arrays? Yours, Kas.
Hi Kassen!
I have a slight issue. I'd like to have a array in which every object itself is a array. Particularly I'd like to have one of 8 locations each of which holds a array of length 32.
I tried this;
int[32] memory[8];
You should be able to do this using a two dimensional array: int memory[8][32]; You can treat this as a matrix or as an array of array. To get the 0th array: memory[0] Should be of type int []: memory[0] @=> int array[]; You can do this up to arbitrary dimensions, just make sure the dimensions add up (the type checker shall complain if they don't). Hope this helps. Ge!
You can do this up to arbitrary dimensions, just make sure the dimensions add up (the type checker shall complain if they don't).
an example: int foo[4][8][32][35]; So... foo[x][y][z][w] is of type int foo[x][y][z] is of type int [ ] foo[x][y] is of type int [ ] [ ] ... foo is of type int [ ] [ ] [ ] [ ] x, y, z, w represent integers in this example. Ge!
an example:
int foo[4][8][32][35];
So...
foo[x][y][z][w] is of type int foo[x][y][z] is of type int [ ] foo[x][y] is of type int [ ] [ ] ... foo is of type int [ ] [ ] [ ] [ ]
x, y, z, w represent integers in this example.
Ok, so in cases like that it's especially important to declare them in the right order. In the 2D case as I understand it you can easily treat a row as if it were a array (which is waht I wanted) but it's less easy to treat a column as one, right? Kas.
Sorry, but I'd like to go into a little more depth because this turns out not to function as I expected. I folowed this; You should be able to do this using a two dimensional array:
int memory[8][32];
You can treat this as a matrix or as an array of array. To get the 0th array:
memory[0]
Should be of type int []:
memory[0] @=> int array[];
And up till here it works. Now I store array[] in memory like this; array @=> memory[0]; That works. Now I make array change based on keyboard input (programing beats in my case). suppose now I'd like to go back to the last stored state. For this I go; memory[0] @=> array; Which I expected to recall my last stored version of the array but in fact it doesn't; this seems to keep "array" identical to what it was. Other things go wrong as well, particularly; I programed some beats (meaning I tured array into something interesting), stored them in memory[0], then made a variation in memory[1], did that again for memory[2]. At that point trying to recall what was in memory[0] results in getting data identical to what is in memory[2] (and so identical to array as well). I believe this to be because I think I'm creating a link between the array and a section of memory while what I'd like to do is copy data from the array to the "memory" where I'd like it to stay the same untill I tell it to change. So... Now what? Copy all numbers one by one? perhaps there is some special syntax or way of unlinking the reference while keeping the data? Hope this is at least somewhat clear? Yours, Kas.
On Aug 4, 2006, at 4:02 PM, Kassen wrote:
Which I expected to recall my last stored version of the array but in fact it doesn't; this seems to keep "array" identical to what it was.
[...]
I believe this to be because I think I'm creating a link between the array and a section of memory while what I'd like to do is copy data from the array to the "memory" where I'd like it to stay the same untill I tell it to change.
Thats the joy/pain of references...
So... Now what? Copy all numbers one by one? perhaps there is some special syntax or way of unlinking the reference while keeping the data?
Copy one by one is the only way to go, as painful as that sounds. This makes a good case for a copy() method in array classes.
Hope this is at least somewhat clear?
Yours, Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Spencer wrote;
Thats the joy/pain of references...
I suspected so. Copy one by one is the only way to go, as painful as that sounds.
This makes a good case for a copy() method in array classes.
Well, it's not all *that* bad, I'm already happy I didn't need to manually define 8 arrays... Thanks for the explanation. Kas.
participants (3)
-
Ge Wang
-
Kassen
-
Spencer Salazar