[closer-devel] using a custom unbound slot marker

Pascal Costanza pc at p-cos.net
Mon Oct 30 12:40:44 UTC 2006


On 30 Oct 2006, at 03:17, Attila Lendvai wrote:

> hi!
>
> i hope someone around here can help me or turn me to the right  
> directions:
>
> i'm generating custom accessors using standard-instance-access and  
> i'd like to use a custom unbound slot value, so i can quickly  
> compare to it with 'eq.
>
> the most obvious idea was to set the slot-definition-initform and  
> slot-definition-initfunction one way or another on the effective  
> slot at some point if it is not already set. i've tried to do that  
> with sbcl several ways, but no luck. somehow i always get the SB- 
> PCL::..SLOT-UNBOUND.. marker even though the initform and  
> initfunction slots are properly set on the effective slot (but  
> probably at the wrong time).

Initforms and initfunctions should be defined for the direct slots,  
the effective slots will then be computed from the direct slots. This  
is important, for example, when you have slots  
with :allocation :class because their initial value is based on the  
direct slots.

Another issue that might bite you is that CLOS implementations are  
allowed to perform some optimizations for slot initializations whose  
effect on the metaobject protocols isn't entirely clear. See the  
notes on shared-initialize in the HyperSpec for more information on  
this (although I recall that SBCL does these things "correctly", that  
is in intuitively expected ways).

Apart from that it's not really clear to me what could go wrong based  
on your description. You may want to post your code here, so I could  
take a closer look.

> does anyone have any experience with this? should i just use SB- 
> PCL::..SLOT-UNBOUND.. directly? that would make it hopelessly  
> unportable...

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...

I hope this helps.


Cheers,
Pascal

-- 
Pascal Costanza, mailto:pc at p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium




-- 
Pascal Costanza, mailto:pc at p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/closer-devel/attachments/20061030/d07abe7c/attachment.html>


More information about the closer-devel mailing list