[elephant-devel] Call SLOT-UNBOUND instead of signaling UNBOUND-SLOT

kmkaplan+elephant at ded.kim-minh.com kmkaplan+elephant at ded.kim-minh.com
Thu Apr 3 13:23:22 UTC 2008


Leslie P. Polzer writes:

>   (defclass pineapple () ()
>     (:metaclass persistent-metaclass))
>   (let ((fruit (make-instance 'pineapple)))
>     (defclass pineapple ()
>       ((tree :initform 1))
>         (:metaclass persistent-metaclass))
>     (slot-value fruit 'tree)))
>
> Will raise unbound slot hell with current code if you have
> a lot of instances. Backends signal UNBOUND-SLOT instead
> of calling SLOT-UNBOUND (which is the more conformant option
> as I see it from CLHS and the MOP spec).
>
> This is also better "do what I mean" behaviour; normally
> when you provide an initform for a slot you rely on never
> having to deal with unbound slots (at least I do).
>
> Attached is a patch which tests this, changes the backend behaviour
> and provides a default for SLOT-UNBOUND that uses the initform
> to fill in the slot value.

This is probably bad: you can't SLOT-MAKUNBOUND anymore.  I have not
yet read and understood all about CLHS 4.3.6.2 but something along
UPDATE-INSTANCE-FOR-REDEFINED-CLASS looks like what's needed.

I can't test it here but the test would look like:

(deftest slot-unbound
    (progn
      (defclass pineapple () ()
        (:metaclass persistent-metaclass))
      (let ((fruit (make-instance 'pineapple)))
        (defclass pineapple ()
          ((tree :initform 1))
            (:metaclass persistent-metaclass))
        (values (slot-value fruit 'tree)
                (progn (slot-makunbound fruit 'tree)
                  (signals-specific-condition (unbound-slot)
                    (slot-value inst 'slot1))))))
    1 t)



More information about the elephant-devel mailing list