2 ms·
Maybe you know that Common Lisp makes it easy to compile and recompile functions at runtime. http://clhs.lisp.se/Body/f_cmp.htm http://clhs.lisp.se/Body/f_cmp.
by mbrock 11y ago
Maybe you know that Common Lisp makes it easy to compile and recompile functions at runtime.
http://clhs.lisp.se/Body/f_cmp.htm http://clhs.lisp.se/Body/f_cmp.htm
In fact, with the package system ASDF, you can recompile (incrementally) an entire package at runtime. This is a single blocking function call; something like:
(asdf:operate 'asdf:compile-op :my-package)
I have a web project where any request in dev mode triggers a system recompilation only if the git revision of the working tree is new.
(my-handler :did-recompile (when (revision-is-new) (recompile) t))
That recompiles the system including MY-HANDLER, and right after RECOMPILE returns, the new version of MY-HANDLER from the working tree will be active.
The way Common Lisp lets me do that as a ten minute hack feels like living in the future... except of course it's pretty old technology!
Edit: I realize this is not really what you are talking about as "self-modifying code." Having full access to the compiler at runtime is a good first step for doing some of what you want, though. And with S-expressions, constructing and manipulating "ASTs" is ridiculously straightforward.