Re: adding a super class

From: Pascal Costanza (costanza_at_web.de)
Date: 10/02/04


Date: Sat, 02 Oct 2004 15:56:57 +0200


Marco Baringer wrote:
> i'm attempting to use the MOP to ensure that classes defined with a
> certain super class always have another class in their class
> precedence list. here's what i've come up with so far [the mopp
> package is just the implementation's MOP package]:

I prefer this approach:

(defclass kobject (standard-object)
   ())

(defclass kclass (standard-class)
   ())

(defmethod initialize-instance
            ((class kclass)
             &rest initargs
             &key direct-superclasses
             &allow-other-keys)
   (declare (dynamic-extent initargs))
   (apply #'call-next-method
          class
          :direct-superclasses
          (adjoin (find-class 'kobject)
                  direct-superclasses)
          initargs))

(defmethod reinitialize-instance
            ((class kclass)
             &rest initargs
             &key (direct-superclasses nil direct-superclasses-p)
             &allow-other-keys)
   (declare (dynamic-extent initargs))
   (apply #'call-next-method
          class
          (if direct-superclasses-p
              (list* :direct-superclasses
                     (adjoin (find-class 'kobject)
                             direct-superclasses)
                     initargs)
            initargs)))

Pascal

-- 
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."