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

Re: change-class



Andreas Dietz <dietz@ticco.ccipe.montp.inserm.fr> says:

> it seems that the CLOS implementation of CLISP does not contain
> CHANGE-CLASS.

This is true. If you want CHANGE-CLASS in CLISP, you can use PCL instead
of the built-in CLOS. But it will be much slower.

> In my problem at hand, I only need to change the class of
> an object, no slots must be added or updated. How can I achieve the
> result of CHANGE-CLASS for this special case?

If you need CHANGE-CLASS (i.e. change an object's class while the
object remains EQ to what it was before), in my opinion you should
rethink about your class hierarchy.

As a general workaround: You can easily achieve your goal by
introducing an indirection class, like this:

(defclass <bozo> () (x y ...))
(defclass <bozo-container> ()
  (indirection accessor: bozo-container-indirection)
)

;; Extend the accessors and any other generic functions so they automatically
;; follow the indirection.
(defmethod bozo-x ((object <bozo-container>))
  (bozo-x (bozo-container-indirection object))
)
(defmethod (setf bozo-x) (new-value (object <bozo-container>))
  ((setf bozo-x) new-value (bozo-container-indirection object))
)
...


             Bruno