[closer-devel] with-active-layers

Pascal Costanza pc at p-cos.net
Fri Feb 16 09:38:49 UTC 2007


On 16 Feb 2007, at 05:37, Igor Plekhov wrote:

> What is the difference between with-active-layers and
> with-active-layers* in ContextL?

You can use with-active-layers in two ways:

(1) Just with layer names:

(with-active-layers (l1 l2 l3)
   ... some code ...)

(2) With additional initargs:

(with-active-layers ((l1 :foo 42))
   ... some code ...)

The second use assumes that the layer l1 has been defined with a  
special slot with :foo as an initarg, for example like this:

(deflayer l1 ()
   ((foo :initarg :foo :special t :reader foo)))

The layer activation (2) additionally rebinds the layer-specific slot  
'foo with dynamic scope.

The two variations with-active-layers and with-active-layers* only  
make a difference when such dynamically scoped rebindings of layer- 
specific special slots are involved. The difference is as follows.  
Assume you additionally have the following layer definition:

(deflayer l2 ()
   ((bar :initarg :bar :special t :reader foo)))

Now let's investigate the following two forms:

(a) (with-active-layers
           ((l1 :foo (bar (find-layer 'l2)))
            (l2 :bar (foo (find-layer 'l1)))
       ...)

(b) (with-active-layers*
           ((l1 :foo (bar (find-layer 'l2)))
            (l2 :bar (foo (find-layer 'l1)))
       ...)

The difference between (a) and (b) is that in (a), the calls (bar  
(find-layer 'l2)) and (foo (find-layer 'l1)) will both see the values  
of the outer bindings for the slots 'bar and 'foo, while in (b), the  
call (foo (find-layer 'l1)) will already see the new binding for the  
slot 'foo, i.e., the value as returned by (bar (find-layer 'l2)) in  
the line before.

This is similar to the difference between let and let*, where all  
variable references in let will see outer bindings, whereas variable  
references in let* will successively see the previously established  
bindings of the same let* form.

No, I don't have a practical use case for with-active-layers*. ;) I  
just wanted to be complete here...

I hope this helps,
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