by ohyes · 9y ago · 0 comments
You can execute arbitrary code at macro-expansion time.
You can also recompile while the process is running, which would include re-macroexpanding.
This is how you get a REPL and other forms of runtime evaluation.
This is kind of the nub of being a dynamic programming language, if it can't do this, it isn't a dynamic programming language. Lisps are generally dynamic programming languages.
Clojure-script might be an exception because of how it is implemented, but Clojure proper on the JVM certainly supports this type of behavior.
I would expect to be able to do (eval `(defun ,function_name () (complicated_macro ,@args))) or (compile `(defun ,function_name () (complicated_macro ,@args)))) at runtime in Common Lisp, without even really considering the consequences beyond whether it is necessary.
It's supposed to work a little bit like if you had an implementation of GCC in the same process as your C program, and you could call GCC from a function to compile some new C code for you to add features or replace existing code. It's powerful + dangerous.