Slots in layers, was Re: [closer-devel] ContextL design question...
Pascal Costanza
pc at p-cos.net
Fri Mar 3 16:30:45 UTC 2006
On 3 Mar 2006, at 03:42, Drew Crampsie wrote:
> Pascal Costanza wrote:
>
>> I haven't extended the with-active-layers construct, though. Here
>> are the reasons:
>> - It would really only look neat when used with initargs instead
>> of accessors. However, the mapping of initargs to actual slots
>> can be changed at runtime in CLOS, so I would have to emit code
>> with quite some overhead here that would determine the current
>> mapping of an initarg to its actual slot. Worse, an initarg could
>> actually be mapped to more than one slot, which would complicate
>> the code even further, with very little reward. I wanted to avoid
>> that.
>
> Sounds like my WITH-SPECIAL-INITARGS construct, which has all the
> drawbacks you mentioned, but simplifies the implementation of Lisp-
> on-Lines significantly.
OK, I will try to integrate this somehow. In order to make this work,
I have started to add the opportunity to declare :initarg options for
slots in deflayer forms. However, this has revealed a few bugs with
regard to special slots with :allocation :class.
I have fixed those bugs and submitted the changes to the darcs
repository. Here are some important remarks:
- :initarg options are now indeed supported in deflayer forms.
- special slots with :allocation :class now work correctly,
especially in conjunction with initialize-instance, reintialize-
instance, shared-initialize, etc. This has led to serious bugs before.
- Singleton classes had an implementation that allowed you to
automagically access :allocation :class slots of a class without
explicitly mentioning its class prototype. This was a bad idea
because those slots could be mixed up with actual instance slots of
the metaclass. So I have removed the magic.
Still, I wanted to make it straightforward to access slots in layers
(as specified in deflayer forms), which are internally turned
into :allocation :class slots. I have achieved this by renaming a few
functions:
- The previous find-layer function is now called find-layer-class,
and returns the layer class.
- The new find-layer function now returns the singleton / prototype
instance of a layer class.
- layer-prototype doesn't exist anymore.
The new find-layer / find-layer-class are quite flexible: You can
pass them layer names, layer classes or layer class prototypes, and
they will return the right thing.
So the following code should work:
(deflayer test-layer ()
((s0 :initarg :s0 :initform 'foo :special t :reader s0)
(s1 :initarg :s1 :initform 'bar :reader s1)))
(s0 (find-layer 'test-layer)) => 'foo
(s1 (find-layer 'test-layer)) => 'bar
etc.
Something like with-special-initargs or with-active-layers that
allows you to use initargs for slots in layers doesn't exist yet.
That's one of the next items on my todo list.
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
More information about the closer-devel
mailing list