Re: [chuck-users] Dynamic Arrays (George Locke)
5. how do you resize an object array? (George Locke) Here's something that should be useful. (from the .pdf ChucK Manual, under Dynamic Arrays, there's more there about it) [64, 65, 60, 59] @=> int notes[]; notes << 58; // notes is [64, 65, 60, 59, 58] notes << 60; // notes is [64, 65, 60, 59, 58, 60] notes.popBack(); // [64, 65, 60, 59, 58] notes << 64 << 65 << 60; // [64, 65, 60, 59, 58, 64, 65, 60]
that works. i'm surprised that the .size method doesn't work, tho, since
it does work on primitive type arrays. I guess there's no instantiation
happening or something...
Thanks!
- George
On Sun, Feb 2, 2014 at 4:24 PM, Perry R Cook
5. how do you resize an object array? (George Locke)
Here's something that should be useful. (from the .pdf ChucK Manual, under Dynamic Arrays, there's more there about it)
[64, 65, 60, 59] @=> int notes[];
notes << 58; // notes is [64, 65, 60, 59, 58] notes << 60; // notes is [64, 65, 60, 59, 58, 60]
notes.popBack(); // [64, 65, 60, 59, 58]
notes << 64 << 65 << 60; // [64, 65, 60, 59, 58, 64, 65, 60]
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
My guess is that it inserts null pointers into the array as you expand it,
which doesn't feel totally unreasonable. For primitives there's usually
intuitive default value that the compiler can use, with objects (that need
allocated resources for their instances, which could be either the declared
type or a subclass), null is the logical default.
On Sun, Feb 2, 2014 at 10:54 PM, George Locke wrote: that works. i'm surprised that the .size method doesn't work, tho, since
it does work on primitive type arrays. I guess there's no instantiation
happening or something... Thanks! - George On Sun, Feb 2, 2014 at 4:24 PM, Perry R Cook 5. how do you resize an object array? (George Locke) Here's something that should be useful.
(from the .pdf ChucK Manual, under Dynamic Arrays,
there's more there about it) [64, 65, 60, 59] @=> int notes[]; notes << 58; // notes is [64, 65, 60, 59, 58]
notes << 60; // notes is [64, 65, 60, 59, 58, 60] notes.popBack(); // [64, 65, 60, 59, 58] notes << 64 << 65 << 60; // [64, 65, 60, 59, 58, 64, 65, 60] _______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users _______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users --
Release me, insect, or I will destroy the Cosmos!
I was getting a bit frustrated, but it is definitely possible to get this
to work properly. I had code that did something like
ar.size(siz);
for (0 => int i; i < siz; i++) {
SinOsc s;
s => ar[i];
}
which didn't work, but changing it to "s @=> ar[i]" *did* work, which makes
sense, since the interpreter/compiler might reasonably think I was chucking
something to ar[i], a null pointer.
I think my grumbling may have been a bit premature in this case.
Thanks for all the help!
- George
On Sun, Feb 2, 2014 at 5:27 PM, Stefan Blixt
My guess is that it inserts null pointers into the array as you expand it, which doesn't feel totally unreasonable. For primitives there's usually intuitive default value that the compiler can use, with objects (that need allocated resources for their instances, which could be either the declared type or a subclass), null is the logical default.
On Sun, Feb 2, 2014 at 10:54 PM, George Locke < george.locke.maxmsp@gmail.com> wrote:
that works. i'm surprised that the .size method doesn't work, tho, since it does work on primitive type arrays. I guess there's no instantiation happening or something...
Thanks!
- George
On Sun, Feb 2, 2014 at 4:24 PM, Perry R Cook
wrote: 5. how do you resize an object array? (George Locke)
Here's something that should be useful. (from the .pdf ChucK Manual, under Dynamic Arrays, there's more there about it)
[64, 65, 60, 59] @=> int notes[];
notes << 58; // notes is [64, 65, 60, 59, 58] notes << 60; // notes is [64, 65, 60, 59, 58, 60]
notes.popBack(); // [64, 65, 60, 59, 58]
notes << 64 << 65 << 60; // [64, 65, 60, 59, 58, 64, 65, 60]
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Release me, insect, or I will destroy the Cosmos!
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (3)
-
George Locke
-
Perry R Cook
-
Stefan Blixt