Skip to content

Latest commit

 

History

History
32 lines (28 loc) · 1.54 KB

eval.md

File metadata and controls

32 lines (28 loc) · 1.54 KB

eval

(eval form)

Evaluates a form given as data. In a macro body, or in a function the body calls, the form lowers in the namespace of the expansion, without the call site's locals, and evaluates over the definitions above the call site. As the program runs, the interpreter, which keeps the program's lowering, lowers the form in the namespace *ns* holds and evaluates it: what it defines the program's later evals, resolves and REPL inputs name, a value no literal spells (a function, an atom) stands in the form as itself, and a form that does not lower throws a clojure.lang.Compiler$CompilerException with the lowering's words. A JVM class does the same: it carries its program and the compiler, lowers the program again at its first run-time eval, and compiles each form into a class linked against itself, so a .class output has the compiler beside it and a .jar inside it. Only a program that may call eval as it runs carries the compiler: the eval of a macro body, or of a function only macro bodies call, runs while the program lowers and adds none by itself, while a program that also expands macros as it runs, or takes that macro's var, may run the body again then and carries it. A wasm module carries no lowering, so there eval at run time throws an UnsupportedOperationException. Also names a function value.

(defmacro compile-if [test then else] (if (eval test) then else))
(def limit 3)
(println (compile-if (> limit 2) :big :small))
(println (compile-if (resolve 'clojure.core/inc) :has :lacks))
:big
:has