[closer-devel] slots on layers

Drew Crampsie drewc at tech.coop
Fri Sep 5 21:27:16 UTC 2008


Hey All,

I have a need for a mechanism similar to the one being described. I
use ContextL with continuations, and i already use something similar
to what Attila was describing. First some example code, with comments.

In LoL we use objects called "descriptions" to control how an object
is displayed. These are essentially layers with per-layer-slot-value
semantics implemented using anonymous layered generic functions.

(define-description bar ())

(define-description foo ()
   ((attribute-with-value :label "A value:" :value 'foo-value))

(define-description foo ()
   ((attribute-with-value :label "A different value:" :value 'foo-in-bar-value))
  (:in-description bar))

(defun display-an (a)
     (format t "~A  ~A%" (attribute-label a) (attribute-value))

(let* ((description (find-description 'foo))
         (attribute (find-attribute description attribute-with-value))

;; set up the environment to describe the object NIL using our description
   (with-described-object (nil description)
      ;; So, executing :
      (display-an attribute)
      ;; will print "A value: FOO-VALUE"

      ;; then if you do
     (with-active-descriptions (bar)
             (display-an attribute) )
      ;; you'll get "A different value: FOO-IN-BAR-VALUE"

     ;; this is implemented via a more general mechanism such that:

      (with-active-descriptions (bar) (setf (slot-value attribute
'label) "A New Label"))
          ;; will set it permenantly in the bar description (layer)
       )
     (with-active-descriptions (bar) (attribute-label attribute))
      ;; => "A New  Label"

This works well for the most part, but the inability to capture the
dynamic environment has lately become a problem. i've been able to
hack it up via manually capturing and re-instating the bindings i
need, but it's a hack and i'm sure there's a better way. Somethimg
like :

In ls2008/9/5 Pascal Costanza <pc at p-cos.net>:
>>> for first-class dynamic closures. The idea would be that you can say
>>> something like (capture-dynamic-bindings), which gives you a first-class
>>> representation of all special variables, which you can later reinstate by
>>> something like (with-reinstated-dynamic-bindings ...). Such a dynamic
>>> closure facility would capture the current representation of active
>>> layers
>>> (because that's in a special variable), as well as, for example, special
>>> slots both in the layers and in other objects.
>>>
>>> (It won't be as general as that, I will have to require registering the
>>> special variables that you want to see captured, but I think I can make
>>> this
>>> relatively non-intrusive

This is exactly what i need. I had a few ideas on how to implement it,
but it's not on my plate right now. I'd really like to see something
like this are part of contextL, as i'm sure it would be much more
thought-out than my implementation :).

>
> I think I can make it work in such a way that it will feel very seamless. My
> idea is that the current context parameter and any special slots defined in
> layered and special classes will be automatically captured by default,
> without you having to worry about anything. I'm very certain that this
> should work (as always, it could have nasty corner cases that I don't know
> about yet, of course).

I'de like to put my vote in for this solution, as it's very much in
line with how i use contextl.   It would enable me to greatly simplify
my implementation in a lot of ways.

I'd be more than happy to get into greater detail, i'm very glad we're
having this discussion! :)

Cheers,

drewc



More information about the closer-devel mailing list