Anonymous user
Runtime evaluation/In an environment: Difference between revisions
Runtime evaluation/In an environment (view source)
Revision as of 16:12, 14 March 2020
, 4 years ago→{{header|Clojure}}
(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}}==
|