[closer-devel] Re: layer slots
Pascal Costanza
pc at p-cos.net
Mon Nov 26 22:32:47 UTC 2007
On 26 Nov 2007, at 20:36, Attila Lendvai wrote:
>> while working on a new architecture for verrazano where backends are
>> layers, i wanted to add slots for layers.
>
> to clarify what i'm trying to achive here: i would like to have slots
> on layers that can hold data for "sessions" when the layer is active.
>
> from a different point of view: i would like to represent verrazano
> backends (that generate cffi/whatever bindings from gccxml output) as
> layers and the layer called 'backend should have a slot called
> 'output-definition-queue that holds the definitions to be output for a
> generation run. then i enable the actual backend layer and i should be
> there initialized on the activated layer.
>
> i've added this to my code:
>
> (defun current-layer ()
> (contextl::layer-context-prototype (current-layer-context)))
>
> and access the slot on (current-layer), but that is accessing a slot
> of the class prototype with all its undesired consequences for my
> use-case.
>
> without contextl i would be doing something very similar: introduce a
> first argument called backend, make-instance a backend instance and
> dispatch on it on all the methods that are now layered methods.
>
> am i misusing layers here?
I am not sure, but I also have to admit that I don't fully understand
the example yet.
However, what you could do is define a slot in a layer as a special
slot:
(deflayer foo ()
((some-slot :initarg :some-slot :accessor some-slot :special t)))
Such a slot behaves like a special variable: It can have different
bindings in different threads. There is a form in ContextL to activate
a layer and at the same time bind such a slot:
(with-active-layers ((foo :some-slot 'some-value))
...)
This activates 'foo and binds some-slot to 'some-value with dynamic
scope (other threads still see the old value of some-slot and the new
binding will be automatically undone on return from that form).
This kind of layer activation is likely somewhat less efficient, since
it involves looking up initialization keywords and calling
reinitialize-instance on the layer prototypes.
A cheaper solution would actually involve to just use dletf:
(with-active-layers (foo)
(dletf (((some-slot (find-layer 'foo)) 'some-value))
...))
Or maybe just a special variable:
(defvar *some-slot*)
(with-active-layers (foo)
(let ((*some-slot* 'some-value))
...))
;)
I don't know which of those comes closer to solving your concrete
problem.
If none of this does the job, please let me know and I will try to
think harder about a better solution...
Thanks for the feedback,
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