Lisp HUG Maillist Archive

MOP and self-reference

Hi,

Assume you want to emulate some tricky relations inside the mop, alog the lines of the example below.
It appears that lisp implementations vary with their interpretation of what to do when the foo metaclass
is reinitialized. Especially, LWW insists on resetting bar superclasses to standard-object. Is there
some simple way to keep what I would expect in the end : bar is still a foo (its metaclass), is still 
an instance of foo, and I can add a slot to foo ?

I welcome any insight on th is topic. Played a lot with it, but still not sure on the right answer.

Best regards,

Fabrice


(defclass foo (standard-class)
  ((x :initarg :x)))

(defmethod sb-mop::validate-superclass
      ((class foo)
       (superclass standard-class))
  t)
(defmethod sb-mop::validate-superclass
      ((class standard-class)
       (superclass foo))
  t)

(defclass bar () ()
  (:metaclass foo))

(format t "~S~%" (sb-mop::class-direct-superclasses (find-class 'bar)))

(reinitialize-instance (find-class 'bar) :direct-superclasses (list (find-class 'foo)))

(format t "~S~%" (sb-mop::class-direct-superclasses (find-class 'bar)))

(defparameter *bar-1* (make-instance 'bar))

(defclass baz (bar) ((y :initarg :y)))

(reinitialize-instance (find-class 'bar)
                       :direct-slots `((:name z :initargs (:z))))

(format t "~S~%" (sb-mop::class-direct-superclasses (find-class 'bar)))

(reinitialize-instance (find-class 'foo)
                       :direct-slots `((:name x :initargs (:x))
                                       (:name new :initargs (:new))))

(format t "~S~%" (sb-mop::class-direct-superclasses (find-class 'bar)))


Re: MOP and self-reference

Unable to parse email body. Email id is 11107

Updated at: 2020-12-10 08:37 UTC