[closer-devel] WITH-ACTIVE-LAYERS does not eval its args. Alternatives?

Pascal Costanza pc at p-cos.net
Sun Dec 1 17:28:38 UTC 2013


On 1 Dec 2013, at 13:56, Pascal Costanza <pc at p-cos.net> wrote:

> Hi Kilian,
> 
> On 1 Dec 2013, at 10:58, Kilian Sprotte <kilian.sprotte at gmail.com> wrote:
> 
>> Hi,
>> 
>> I have run into a situation, where I would want WITH-ACTIVE-LAYERS to
>> evaluate its layer arguments or to have an alternative construct which
>> does so.
>> 
>> My questions are:
>> 
>> 1. Is there a reason for WITH-ACTIVE-LAYERS to be designed this way?
> 
> Yes, the macro version can be implemented more efficiently, because you already know at macro-expansion time what layers to activate.
> 
>> 2. Is there an alternative that allows me to achieve the desired
>> effect?
> 
> Yes. adjoin-layer and remove-layer allow you to programmatically create new combinations of layers. You need to pass one layer and a “layer context”, which is an already composed set of layers. You need to call adjoin-layer and remove-layer several times if you want to compose several layers, because composition ordering matters. current-layer-context gives you a context of the currently active layers. So adjoin-layer, remove-layer, and current-layer-context in combination are the functions to compute new sets of layers.
> 
> Once you have a new layer context, you can use funcall-with-layer-context or apply-with-layer-context to execute a block of code within that context.
> 
> Such contexts are first-class, so you can store them and pass them around.

A bit more detail: For example, you can also do something like this.

(defvar *some-context*
  (with-active-layers (l1 l2 l3)
    (current-layer-context)))

…and then later…

(funcall-with-layer-context *some-context* (lambda () (do-this) (do-that)))


Pascal

--
Pascal Costanza






More information about the closer-devel mailing list