[closer-devel] using a custom unbound slot marker

Attila Lendvai attila.lendvai at gmail.com
Mon Oct 30 12:50:55 UTC 2006


>
> One trick I have used once is to just inspect the unbound value that is
> used by the CLOS implementation. You can do this in a portable way, like
> this:
>
> (defclass test ()
>   (test-slot))
>
> (defvar +unbound-slot-value+
>   (let ((test (make-instance 'test)))
>     (standard-instance-access test
>       (slot-definition-location
>         (find 'test-slot (class-slots (find-class 'test))
>               :key #'slot-definition-name)))))
>
> (setf (find-class 'test) nil)
>
> This code assumes that the value for unbound slots remains constant for
> the lifetime of an image (but I can't imagine why that would not be the
> case).
>
>
> I think it's a pity that the CLOS MOP doesn't just specify a constant for
> this. Maybe I should add this to Closer to MOP...
>

at least one of your users would welcome that new feature! ;)

I hope this helps.
>

yep, thanks for the clarification. for now we'll be sbcl-only in
computed-class <http://common-lisp.net/project/computed-class/> (it's like
cells, but we rolled our own to be better integrated with mop and cleaner
inside)

after i've resolved some finaly oddities i'll push the changes to the online
repo (which is quite a bit outdated by now), probably later today. but i'll
drop the idea of overriding the unbound slot marker for two reasons:

   1. it's probably a little slowdown
   2. more complex and probably more fragile solution then your
   +unbound-slot-value+ idea.

on a sidenote: sbcl has no setf standard-instance-access (not demanded by
the standard, but still) which is trivially implemented by:

(defun (setf standard-instance-access) (new-value instance location)
  (setf (clos-slots-ref (std-instance-slots instance) location) new-value))

i'll send a patch to the sbcl list.

thanks again!

-- 
- attila

"- The truth is that I've been too considerate, and so became
unintentionally cruel...
- I understand.
- No, you don't understand! We don't speak the same language!"
(Ingmar Bergman - Smultronstället)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/closer-devel/attachments/20061030/8bf0008d/attachment.html>


More information about the closer-devel mailing list