3 ms·
Lisp objects are the abstract syntax tree of a data notation. E.g the semantics of (a b 3) is that "I am a list of two symbols and an integer"; and the object w
by kazinator 4y ago
Lisp objects are the abstract syntax tree of a data notation. E.g the semantics of (a b 3) is that "I am a list of two symbols and an integer"; and the object which results from that is the abstract syntax which captures that exact structure and meaning: it is a list object, with symbol objects in it, and an integer. That object is that what the S-expressions says it denotes.
There is no code AST there which says "I'm a call to function a with two arguments".
Lisp evaluation/compilation is the imposition of code semantics on an abstract syntax that is concerned only with data. No, not just code semantics, but syntax and semantics. The Lisp code view of data imposes additional syntax (sometimes) which isn't represented.
Macros definitely implement syntax. They have a run-time, but that is not really relevant, except for macros that have weird side effects, or interact with the environment (read from files).
Lisp macros sometimes parse nested syntax beyond just accessing positions in the data; like the example of the loop macro, which recognizes a phrase structure grammar defining the loop clauses.
We can have a macro (infix a + b * c) which performs operator precedence parsing, producing (+ a (* b c)). That macro is doing nothing but providing syntax; it doesn't care what the symbols mean beyond their arity, associativity and precedence.
Some Lisp compilers go straight from the data AST (after macroexpansion) to code. Others build an actual code AST for doing multiple passes. There may be nodes in there like function-call and variable-binding and whatnot. CLOS objects could be used, etc.
This is the key insight: the AST concept can exist in more than one way in the same situation involving the same pieces. A S-expression denotes data. That data is its AST. That AST potentially denotes code. But not as abstract syntax: the S-expression's AST is abstract toward the S-expression, but serves as entirely concrete syntax for code. The concrete syntax has some of the benefits of an AST, because it exhibits nesting, and can eliminate the need for a secondary AST.
Think about a Common Lisp function definition with optional arguments (defun foo (a &optional b c)). That data structure is not abstract syntax: it includes the concrete punctuator &optional.
Abstract syntax needs an abstraction like a "function-definition" object, which has "optional-arguments" as a property --- and no sight of any &optional punctuator any more. To get there, we must parse the function definition; scanning the parameters for the presence of &optional, and &rest, &key, &aux.
For us to have a code AST node, the &optional word must be gone, for exactly the same reason that parentheses are gone from the S-expression when it becomes a data AST.
- lispm 4y agowell written