Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Once compiled, can a program hypothetically run without ever calling eval?

I'm in the process of learning how Clojure works and I'm wondering if it would be possible (just for the sake of understanding how Clojure and Lisps dialects do work in general) to compile a Clojure program and then to run it while "forbidding" the use of eval.

Note that I'm not asking if it would be technically possible to, say, hotpatch a running Clojure program so that once compiled a Clojure program would throw an exception should eval ever be called.

What I'm asking is that if it is technically possible to forbid the use of eval, would most Clojure programs not using a REPL and not specifically eval still work?

Or are the default / built-in APIs / macros / functions using eval under the hood at runtime?

like image 493
Cedric Martin Avatar asked Dec 20 '22 12:12

Cedric Martin


1 Answers

eval is what brings the interactive programming to Clojure (and Lisps). You don't need eval once you have compiled Clojure code to jvm byte code (which doesn't use eval function call anywhere), or other Lisp dialects to their targeted runtime (mostly native code).

eval main purpose in an application would be to generate code at runtime and execute it, basically it would allow to create "runtime macros", which isn't what the core API of the language need to do for what it does.

like image 79
Ankur Avatar answered May 07 '23 05:05

Ankur