Anonymous user
Runtime evaluation/In an environment: Difference between revisions
Adds Clojure solution
(newer Tcl idiom) |
(Adds Clojure solution) |
||
Line 84:
<pre>16
25</pre>
=={{header|Clojure}}==
We must define x as global, but we use dynamic bindings. Only functions within the binding will see the newly bound value of x, before it re-establishes the bindings that existed before.
<lang clojure>(def ^:dynamic x nil)
(defn eval-with-x [program a b]
(- (binding [x b] (eval program))
(binding [x a] (eval program))))</lang>
<lang clojure>(eval-with-x '(* x x) 4 9)
=> 65</lang>
=={{header|Common Lisp}}==
|