[chuck-users] Doing something to all members of a class?
ssalazar at CS.Princeton.EDU
Wed Mar 14 00:57:57 EDT 2007
On Mar 13, 2007, at 9:49 PM, Scott Wheeler wrote:
> The only way I saw to work around this was creating another class
> as an array handle and using that by reference.
Another potential workaround for this bug would be to declare an
empty array, which allocates no memory for array elements, is "sort
of" like an array reference, and manages to get around the static
data member bug. You can then to chuck a new array to it to
initialize it. E.g.,
int values @=> Foo.values;
static int values;
One technique I like is to initialize static class data at the
beginning of the file containing the class definition. The
advantages of this approach are that the initialization is guaranteed
to be executed only once, is guaranteed to be executed if no fatal
errors occur during the initialization, is executed before anything
else can use it (though Im not positive this is guaranteed), and
doesn't require an instance of the class to have already been
created. If the class definition is at the top of the file, it
sometimes makes sense to put the initialization code immediately
after the class definition, which is functionally the same but might
read a little better.
> And unlike other objects, it seems that you can't assign an array
> to an Object. (i.e. "new int @=> Object foo;" doesn't work)
This now works as of the current release candidate! However, I dont
think there is a way to get the array data out of an object stored in
an Object reference (foo $ int doesn't work).
More information about the chuck-users