[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: shen@schemer.Jpl.Nasa.Gov (Sheldon Shen)
- Subject: Re: CLOS
- From: email@example.com
- Date: Mon, 23 Dec 1991 15:01:21 -0500
- Cc: info-mcl
>I am trying to convert code from 1.3.2 to 2.0. Here are some questions:
>In MACL 1.3.2, I can use
>(ask an-object (have 'a-new-attribute "something")) to add
>an attribute to an object at run time. Can you do this in
>MACL 2.0b? (When an object is defined, a user may only know
>part of the attributes.)
CLOS has no concept of dynamic slots. You must know all of the
slot names at DEFCLASS time. You can easily add an alist slot
which stores dynamic values, though, and use the SLOT-MISSING
generic function to access it from SLOT-VALUE, SLOT-BOUNDP, and
SLOT-MAKUNBOUND. I have code to do this, if you're interested.
>I could not find "do-object-variables", "object-parents",
>"object-children" in MACL 2.0b (Do you have to write your
>own code to traverse an object hierarchy in 2.0?) . I do
>find, however, "slot-definition-name", "class-slots" in
>someone's 2.0 code. They seem to come with 2.0. Where can
>I find the documentations for these?
There is no concept of object-children in CLOS. An instance knows
its class, but a class does not know its instances. This allows
instances to be garbage collected. You can write methods for
ALLOCATE-INSTANCE which maintain a list of instances for a class.
Here is partial documentation of the part of the CLOS Metaobject Protocol
(MOP) that is supported by MCL. More complete documentation will be part
of the MCL manual that ships with the final version of MCL 2.0.
Returns a list of the direct superclasses of the given class (the
classes that were mentioned in its DEFCLASS form).
Returns a list of the direct subclasses of the given class (all the
classes that include this one in their DEFCLASS form).
Returns a class'es precedence list: a list of class objects.
Returns a list of the methods which specialize on the given class.
Will be slot the first time it is called as this information is
not normally cached.
Returns a list of the generic functions which have methods that specialize
on the given class. Will be slow the first time it is called.
Returns a cons, the car of which is a list of slot definitions for
the class slots of the given class and the cdr of which is a list
of slot definitions for the instance slots of the given class.
same as class-slots, but returns only slot definitions for slots which
are local to the given class (mentioned in its DEFCLASS form).
Returns the name of a slot definition object. slot definition objects
are currently represented as lists, but this will likely change in
a future release of MCL.
Note that in MCL 2.0 final, the functions CLASS-DIRECT-SLOTS and
CLASS-SLOTS will be replaced by the functions CLASS-DIRECT-CLASS-SLOTS,
CLASS-DIRECT-INSTANCE-SLOTS, CLASS-CLASS-SLOTS, and
CLASS-INSTANCE-SLOTS, which can be defined for 2.0b1 as follows:
(unless (fboundp 'class-direct-class-slots)
(defun class-direct-class-slots (class)
(car (class-direct-slots class))))
(unless (fboundp 'class-direct-instance-slots)
(defun class-direct-instance-slots (class)
(cdr (class-direct-slots class))))
(unless (fboundp 'class-class-slots)
(defun class-class-slots (class)
(car (class-slots class))))
(unless (fboundp 'class-instance-slots)
(defun class-instance-slots (class)
(cdr (class-slots class))))
? (defclass foo ()
((x :initform 'x-value :accessor foo-x :initarg :x)
(y :initform 'y-value :accessor foo-y :initarg :y)))
? (class-direct-instance-slots (find-class 'foo))
((X (X-VALUE) (:X)) (Y (Y-VALUE) (:Y)))
? (slot-definition-name (car *))
Returns a prototypical instance of the given class.
Not defined for built in classes. The resulting instance has undefined
instance slot values.
Returns the name of a method object.
Returns the generic function associated with a method, or NIL
if there is none.
Returns a list of the specializers of a method
Returns a list of the methods of a generic function