3 ms·
How is a list (of nested lists) not a tree?
by ndr 2y ago
How is a list (of nested lists) not a tree?
- lispm 2y agoIt could theoretically be a graph. For example I can make a circular list being a part of the source and the macro may process it. Get the first two items from a list and add them: CL-USER 21 > (defmacro add-2 (a) (list '+ (first a) (second a))) ADD-2 Now we construct a circular list and use the macro: CL-USER 22 > (add-2 #1=(1 2 3 . #1#)) 3 The circular list is really a part of the source code: CL-USER 23 > '(add-2 #1=(1 2 3 . #1#)) (ADD-2 #1=(1 2 3 . #1#)) Another example: One could pass in a string and have the macro parse the string...
- aidenn0 2y agoIt usually is a tree, just not a syntax tree. For example, the "if" special form in CL has the syntax: (IF <text-expr> <then-expr> [<else-expr>]) But appearing in a macro expansion, it would just be a list where the first item was the symbol "IF" from the "COMMON-LISP" package. In addition, you could put e.g. (IF foo bar baz biff quux) Inside the body of a macro you would get a list that does not match the syntax of the "if" special form, despite superficially looking like such a list. This doesn't match anything that one would call an "AST" in other languages, which would enforce syntactical correctness of special forms.