[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: insert classes?



    Date: Tue, 20 Mar 90 16:01:51 EST
    From: Joseph.Bates@WIZARD.OZ.CS.CMU.EDU

    Danny Bobrow writes,

       Assume you had started with

       (defclass a (b) ...)

       ...
       Then 

       Evaluate 
       (defclass c (b) ...)      [*] [referenced below]

       and then evaluate:

       (defclass a (c) ...)

       CLOS guarantees that the new definition will override the old one
       and that instances of a will be updated to the new structure the
       next time a method is called on them.

    But this requires that the definition of A still be available when C
    is to be inserted.  Is it possible to do the insertion without having
    to retain the text of the definition of A?  That is, using only the
    info on the line tagged by [*] above?  (Or perhaps also using the
    knowledge that A is a subclass of B.)

    Joe Bates

Sorry for the delay; I was away.

The problem you mention is one reason for have a metaobject protocol,
with classes as first class objects. So to do what you want,

(defclass c (b) ...)

and then

(reinitialize-instance	(find-class 'a)
			:direct-superclasses (list (find-class 'c)))


This will change the direct-superclasses of A without affecting the
rest of its definition (e.g. slots defined, accessors).


This works in Rainy Day PCL.