Jump to content

Runtime evaluation/In an environment: Difference between revisions

(Add Jsish)
Line 125:
=> 65</lang>
 
Here's another version which avoids the global by compiling a local function with a single argument x (the ~'x is how to avoid automatic namespace qualification of symbols in a syntax quote):
<lang clojure>
(defn eval-with-x [program a b]
(let [func (eval `(fn [~'x] ~program))]
(- (func b) (func a))))
</lang>
<lang clojure>(eval-with-x '(* x x) 4 9)
=> 65</lang>
 
=={{header|Common Lisp}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.