You can combine let and binding like this to make this slightly more
elegant:

(let [a# 'expr involving *A* *B* and *C*''
      b# 'expr involving *A* *B* and *C*''
      c# 'expr involving *A* *B* and *C*'']
  (binding [*A* a#
               *B* b#
               *C* c#]
     ...))

Note the x# form which does an implicit gensym for you so you get
unique names.

This at least reduces it from n levels to two levels. It would be
pretty easy to build a parallel-binding macro that did this for you.

hth,

Tom


On Feb 17, 10:09 am, Yaron <ygol...@gmail.com> wrote:
> I did but it requires two levels of macro and that made me nervous.
> The problem is derived values. When defining a binding, near as I can
> tell, the values in the binding cannot see other values in the
> binding. In other words:
>
> (def *A* 10)
> (binding [*A* 3 B (+ foo 1)] B)
>
> Returns 11, not 4.
>
> So to use the macro I have to:
>
> (def *A* bogus_value)
> (def B bogus_value)
>
> (defmacro in-environment [env & body]
>   `(binding [*A* :A ..]
>     (binding [B (+ *A* 1)...]
>     �...@body))
>
> I think this would actually work. But it requires a bunch of
> accounting (all the bogus global defs) and introduces some worrisome
> ordering issues. For example, let's say I have a value C whose
> definition is (def C (+ B 1)). I can't define it using the previous
> macro. Because, again, bindings can't see each other. So now I'd have
> to write a macro that dynamically created a whole set of nested
> bindings. Which seems like a lot of work.
>
> In other words:
>
> (binding [*A* :A...]
>   (binding [B (+ *A* 1)...]
>    (binding [C (+ *B* 1)...]
>      etc.
>
> And I can't use let (which does allow for internal visibility) because
> then other functions I call will bind to the global value not the let
> value.
>
>    Yaron

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to