4 ms·
Here's a perhaps better CL example as it side-steps the non-shadowability of the common-lisp math operators: (+ (flet ((f (a) (* a a))) (f 10)) 2) This woul
by pflanze 8y ago
Here's a perhaps better CL example as it side-steps the non-shadowability of the common-lisp math operators:
(+ (flet ((f (a) (* a a))) (f 10)) 2)
This would, as I already mentioned, require the code walker to support flet, and also pass around a lexical context so that the additional bindings are known. (And then handle such functions, probably by inlining them.)
(I had some discussion on #lisp on freenode.)
Anyway, the point I wanted to make in all of this is just to remind people that the meaning of S-expressions is context sensitive, more so than ASTs in most languages. Actually Wikipedia[1] puts contextual analysis as a step after ASTs, so given that, perhaps I was wrong saying that S-expressions are not ASTs, but still it's important to keep in mind that there's a difference from ASTs in most languages. Macros do implement syntax that languages without them would need special parser support for; hence I think of macros as being kind of a continuation of parsing (first step: string to sexpr, second step: macros, then the compiler does the syntactical analysis; if you want to implement derivation of a language enriched with context dependent stuff, then you'd have to hook into the compiler, or do the same context analysis that the compiler is doing).
[1] https://en.wikipedia.org/wiki/Abstract_syntax_tree https://en.wikipedia.org/wiki/Abstract_syntax_tree
(Perhaps also see https://en.wikipedia.org/wiki/Abstract_semantic_graph https://en.wikipedia.org/wiki/Abstract_semantic_graph )