[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: accessing default values in classes
- To: commonloops.pa@Xerox.COM
- Subject: RE: accessing default values in classes
- From: "Peter N. Saurugger" <firstname.lastname@example.org>
- Date: Sun, 4 Feb 90 19:30:01 CST
- Cc: email@example.com, firstname.lastname@example.org, email@example.com
- Redistributed: commonloops.pa
Here is my original question:
I would like to find out whether there is a defined way of accessing the
default values in classes. The accessors seem to work only with instances
I probably should point out why I would like to have this feature: I am
currently building a blackboard-based system. This system reasons about
strings of instances of pre-defined classes. Under certain circumstances
(e.g. data input) I need to create an object which matches to the default
value of a certain slot. It seems that I have to create a dummy instance
for each class to be able to access these values ...?
Here is a suggestion by firstname.lastname@example.org :
Slot descriptions are kept on the class, so you can access the default
value with something like:
(defun default-value (slot-name class)
(slotd-initform (find-slotd 'name (class-slots class))))
Alternatively you could create a default instance, as you suggested,
and then just get a slot value using an accessor.
-- this works nicely in the case where I used the :initform slot option,
but slotd-initform does not access default-values (a class-option). Anyway,
this brought me on the track to a possible route, using the accessor
class-options on a class-object.
Here is another suggestion by John E. Collins (email@example.com)
Isn't this what class-prototype is for? It seems to me that
returns something that looks like a "default" instance of the class in
question. You can then access it as a normal instance. I have
several times used this to get at class-allocation slots when I didn't
have ready access to an instance of the class.
-- This doesn't work in the version of pcl (Victoria day) I have up.
The method class-prototype was redefined to use allocate-instance
instead of make-instance (as it had been before). ALLOCATE-INSTANCE
leaves the slots of the returned prototype unbound.
Thank you for your suggestions,
--Peter N. Saurugger
Molecular Biology Computing Center