eval


Form

(eval expr)

eval compiles and executes expr at runtime.

Evaluation uses the current lexical environment first, then global bindings and builtins.

exprResult
Number, string, boolean, and other self-evaluating valuesReturned unchanged
SymbolResolved in current lexical scope, then globals/builtins
List or pairCompiled and evaluated as code
Other heap valuesReturned unchanged

Error behavior


Examples

(eval '(+ 1 2))                           ; => 3
(let ((x 10)) (eval '(+ x 5)))           ; => 15
(let ((x 10))
  (let ((f (lambda (y) (eval '(+ x y)))))
    (f 7)))                               ; => 17

Runtime tag preservation:

(catch 'runtime.type-error
  (eval '(car 1)))

User tag preservation:

(catch 'my-tag
  (eval '(raise 'my-tag 7)))

Notes