Christophe Grand a écrit :
> You also can do something like this:
>
> (defmacro let-eval [vars expr]
> (let [bindings (mapcat #(list (list `quote %) %) vars)]
> `(eval (list 'let [...@bindings] ~expr
>
Hmm... not quite:
user=> (let [x [2 3]] (let-eval [x] '(rest x)))
(3)
user=> (let
Greg Harman a écrit :
> One solution is to use (binding), which still requires a global var,
> but gives each eval it's own binding of that var:
>
> user=> (def x)
> #'user/x
> user=> (def expr '(+ x 4))
> #'user/expr
> user=> (binding [x 3] (eval expr))
> 7
> user=> x
> java.lang.IllegalStateExce
Nathan,
Just to confirm two things in eval-expr:
1. Should seq be seq?
2. It looks like you still need to a. have a global x defined to
evaluate eval-expr and b. need to wrap the call to eval-expr with
binding in order to get a non-global binding for x (let doesn't seem
to do the trick).
-Greg
On Sat, Jan 17, 2009 at 11:06 AM, Greg Harman wrote:
>
> Meta: This thread is a revival and continuation of last month's
> discussion at:
> http://groups.google.com/group/clojure/browse_thread/thread/e1226810b6ac7bfc/8e0f53c141c26fcc?lnk=gst&q=eval+binding#8e0f53c141c26fcc
>
> ---
>
> Nathan, did
Meta: This thread is a revival and continuation of last month's
discussion at:
http://groups.google.com/group/clojure/browse_thread/thread/e1226810b6ac7bfc/8e0f53c141c26fcc?lnk=gst&q=eval+binding#8e0f53c141c26fcc
---
Nathan, did you ever come up with a better way to do this than using a
global v