[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" <peter-s@molbio.cbs.umn.edu>
- Date: Sun, 4 Feb 90 19:30:01 CST
- Cc: kanderso@dino.bbn.com, norbert@molbio.cbs.umn.edu, us015029@mmm.serc.3m.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
for me.
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 kanderso@dino.bbn.com :
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.
k
-- 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 (us015029@mmm.serc.3m.com)
Isn't this what class-prototype is for? It seems to me that
(class-prototype some-class-object)
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
UofMN