Compiled eval Limitations
eval works in all three backends. In the interpreter it is the full tree-walking evaluator. The WASM and JVM compilers each emit a small tree-walking interpreter into their output (_eval/_apply/_store plus the helpers _envLookup/_lookup) that runs the form at runtime, so no separate evaluator or parser is needed.
The compiled eval (WASM and JVM) implements a lexical environment plus a persistent global environment, and aims for parity with the interpreter: self-evaluating atoms, variable references, closures, the special forms and higher-order functions (let, lambda, cond, while, setq, setf, push, pop, funcall, apply, mapcar, mapc, reduce, nested eval, ...), the built-in macros, and application of any function or interpreted closure all behave as in the interpreter. Rather than enumerate everything, the differences are listed below.
Compiled eval limitations
The compiled eval (WASM and JVM) differs from the interpreter only in these cases:
- A
lambdabuilt at runtime does not parse lambda-list keywords. Compileddefun/lambdaforms support&optional/&rest/&key(desugared at compile time), and calling such a compiled variadic function fromevalworks. But a lambda that only exists inside an eval'd form, e.g.(eval '(funcall (lambda (&rest r) r) 1 2)), binds its parameters positionally —&restis treated as an ordinary parameter name — and its argument count is not checked. A runtime lambda without lambda-list keywords reports a wrong argument count as aprogram-error, as the interpreter does. A definition handed tocompileby the program's own top-level definitions is compiled ahead and is not subject to this. - Global variables are shared between compiled code and
eval. Asetq/defvar/defparameter/defconstantmirrors its value into the runtimeevalglobal environment, so an eval'd expression can read a global the compiled program defined (e.g.(setq add10 (make-adder 10))then(eval '(funcall add10 100))returns110). An eval'd assignment (setq,setf,push,pop) of such a variable writes the compiled variable as well, so compiled code sees it. A special variable (defvar/defparameter, in the program or in an eval'd form) is read and assigned through its current dynamic binding, as compiled code does, and an eval'dletof one binds it dynamically: a function it calls sees the binding. A(set ...)-- or(setf (symbol-value ...) ...)-- writes both as well. Only global variables are mirrored: a lexical of a top-level form -- alet/loop/dovariable -- is not, matching Common Lisp, whereevalevaluates in the null lexical environment ((let ((x 5)) (eval 'x))reads the globalx, and signalsunbound-variablewhen there is none, on every backend). pprint-logical-blockis not supported. The other built-in macros are, along withblock,return-from,tagbody,go,catch,throw,unwind-protect,progv,fletandlabels: a table of run-time expansions covers them, and an eval'ddefvarmakes its name special.pprint-logical-blocksignalsundefined-functionnaming it, as any operator no function answers does. In a file read by a runtimeload,in-package,defpackageanddeclaimare not processed and answernil.- A symbol macro an eval'd form defines exists only for eval'd forms, and a program's own top-level
define-symbol-macroonly for its compiled code. An eval'ddefine-symbol-macrois read and assigned through its expansion by later eval'd forms. A top-level one of the program is consumed when the program compiles, likedefmacro, so an eval'd form does not see it. An&environmentparameter of an eval'dmacroletis nil. setfof a place reachescar,cdrand their compositions,first...tenth,rest,nth,gethash,aref,svref,row-major-aref,elt,char,schar,getf,get,slot-value,symbol-valueand any place with a(setf name)function the program defines, adefclassaccessor among them. An eval'd form assigning any other place, a structure accessor or a(setf name)function only an eval'ddefundefines among them, assigns nothing.- The standard functions, variables and macros a form can reach depend on how the program builds it. Functions resolve through the registry of the functions compiled into the output. Most are always there;
typep,coerce,aref,format,error,sqrtand the like, and the run-time expansion of a macro, are compiled in only for a program that names them, and a form the program spells as data names them:(eval '(typep x 'integer)),(eval (list 'aref v 0))and(eval '(dolist (x l) (print x)))work. A form read or built at run time ((eval (read)),(eval (intern name)), a runtimeload) can name anything, so such a program carries every standard function and variable, which makes it larger. The exceptions aresleep, which on--componentputs the module in async mode, andload, which keeps every library definition from being pruned: the program has to name them. defmacroand backquote are compile-time only. On the compilation path, user macros are fully expanded (and their definitions consumed) before the compilers run, and backquote templates are expanded by the reader; the runtimeeval/readof a compiled program recognizes neitherdefmacronor the backquote character. The same holds formacroexpand/macroexpand-1: a call with a literal quoted argument is folded to its expansion at compile time, and in the runtimeevalthese functions signal an error (gensym, by contrast, works — it has a first-class wrapper).defstructis compile-time only. A top-leveldefstructis expanded into its generated functions before compilation, so calling a constructor/accessor/predicate fromevalworks, but an eval'd form can neither define a new structure nor use an accessor as asetfplace. A#S(...)literal is likewise resolved before compilation, so it is not recognized insideevaleither.- The CLOS subset is compile-time only. Like
defstruct, top-leveldefclass/defgeneric/defmethodforms are expanded before compilation — calling a generic function, a reader/accessor, or a constructor fromevalworks, but an eval'd form cannot define classes or methods. - The
rontolisppackage functions are not supported.rontolisp:version,rontolisp:fetch,rontolisp:http-handler,rontolisp:await,rontolisp:futurep,rontolisp:json-parseandrontolisp:json-stringifyare compiled directly (constants, inline calls or spliced-in library functions); in the runtimeeval/loadthey signalundefined-function.
These differences come from the design: the runtime eval resolves operators by name against a compile-time registry of the functions that were actually compiled into the output, and built-in functions are shared with the compiled code.