[Prev][Next][Index][Thread]
Need help with Class-Allocated Slots
I've been playing around with slot allocation and am wondering if there is a
way to access "class allocated" slots without having an instance of that
class?
Here's an example:
// ====================================================
// <bookkeeping-class>
//
// - a class that keeps track any instances created
// ====================================================
define class <bookkeeping-class> (<object>)
class slot all-instances :: <list>,
init-value: #();
each-subclass slot class-instances :: <list>,
init-value: #();
end class;
// initialize
//
define method initialize (a :: <bookkeeping-class>, #keys)
next-method(a);
a.all-instances := add(a.all-instances, a);
a.class-instances := add(a.class-instances, a);
end method;
// ====================================================
Now, if I instanciate any number of instances of this class (or
sub-classes), and I have an instance, I can get the list of all instances;
// ====================================================
let node = make(<bookkeeping-node>);
let instance-list = node.all-instances;
// ====================================================
This works, but I have to create a "dummy" instance to get access to the
instance list(s). Then, I have to "remove" the dummy instance.
What I would like to do is, given the class, get all of the instances;
// ====================================================
// hacked-up syntax
let instance-list = <bookkeeping-node>.all-instances;
// ====================================================
I've been looking through the DRM, and there aren't too many examples of
class-allocated slots.
Language lawyers - any ideas?
Thanks,
Ron Franke-Polz
Follow-Ups: