3 ms·
Lisp macros directly manipulate the program's abstract syntax tree (in the case of Lisp, it happens to hava a 1-1 relationship to the source code structure). It
by dangerbird2 9y ago
Lisp macros directly manipulate the program's abstract syntax tree (in the case of Lisp, it happens to hava a 1-1 relationship to the source code structure). It's more comparable to a web app's html templater than a syntactic macro system like Lisp's.
- phoe-krk 9y agoIt doesn't strictly have a 1-1 relationship because of macros themselves. They're Turing complete, so the same macro can expand into different ASTs based on user input during compilation, presence of any files on the hard drive or even moon phases, so I have to say that this relationship is much more complicated than a simple 1-1. For very simple functions like (lambda (x) (* x x)) this is true, but macros' power greatly complicates it.
- dangerbird2 9y agoI should have said a read and macroexpanded lisp source has a 1-1 relationship with the AST. As an aside, the bigger distinction between something like C++ template metaprogramming and Lisp metaprogramming is that while C++ uses a template language completely orthogonal to the runtime language, Lisp macros is nothing more than Lisp code executed at macroexpand-time rather than eval-time.
- kazinator 9y agoA Lisp form with unexpanded macros has abstract syntax; the unexpanded macro forms are AST material.