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

Re: slot-unbound



> I was attempting to define methods for the generic function
> slot-unbound in different packages for different classes of
> objects.  MCL 2.0.1 seems only to recognize the method defined
> on STANDARD-OBJECT. Am I overlooking something? 

The first argument to slot-unbound is the class of the instance, so methods 
should specialize that argument on the metaclass.  The second argument should
be specialized on the particular class.

> (in-package :small-package)
> 
> (defclass small-object ()
>   ((slot-1 :initarg :slot-1 :accessor slot-1)
>    (slot-2 :initarg :slot-2 :accessor slot-2)))
> 
> (defmethod slot-unbound ((class small-object) instance slot-name)
>   (declare (ignore slot-name))
>   (declare (ignore instance))
>   'unbound)

(defmethod slot-unbound
           ((class standard-class) (instance small-object) slot-name)
  (declare (ignore slot-name))
  'unbound)

> (eq (slot-1 (make-instance 'small-object)) 'small-package::unbound)
> ;;==> NIL

With the new definition above, this returns T.