4 ms·
If you can compile code at runtime, then how are you not able to use macros at runtime via the same facility? Macros are just functions that operate on the data
by eduction 4y ago
If you can compile code at runtime, then how are you not able to use macros at runtime via the same facility? Macros are just functions that operate on the data structures that define function calls prior to those calls being executed, symbols resolved , etc. So if you’re compiling new code at runtime via eval the that code will go through the same process, including macro expansion.
- Tomte 4y agoThe point was that macros are not special, they don't give you anything more for "self-modification".
- eduction 4y agoMacros are special in the sense that they are expressly intended to modify code. I take your implied point that at runtime there is not really a difference between a function designed to rewrite code data structures and evaluate them vs calling macroexpand and using a predefined macro. But it’s going to be more concise at least to do the latter. It’s also probably the case that when people talk about lisp macros they are including facilities that can be used anywhere but are mainly used for macros - backtick quoting, unquoting forms, etc. - as well as macro like activities like having a function designed to rewrite a code data structure at runtime prior to it going to eval (even if defined with defn or defun rather than defmacro).
- lispm 4y ago> Macros are special in the sense that they are expressly intended to modify code Macros are intended to transform code. They are designed such that in compiled code the transformation is only done at compile time.
- lispm 4y agoIf you are going to use EVAL at runtime, then macros don't buy us anything new. calling (eval (generate-some-code)) does already execute newly generated code at runtime.