3 ms·
Correct, that's where for example an interpreter walks the code and builds up the understanding. Similar a compiler, a code walker or other tools. The shallow
by lispm 3y ago
Correct, that's where for example an interpreter walks the code and builds up the understanding. Similar a compiler, a code walker or other tools.
The shallow view allows in Lisp to provide new/different views of code. That's good and bad. Many transformations of code don't need a deep understanding, many do. In Lisp I can write (infix 3 + 1 * sin (x)), because an infix macro can provide its own interpretation, by transforming the code. But then I need to parse the code and find out what the things are: variables, literals, operators, calls, ...
For example when I want to substitute FOO with a call:
CL-USER 34 > (LET* ((FOO 10) (BAR (+ FOO 32)))
(symbol-macrolet ((foo (print 2)))
(* foo bar foo bar foo ; 1-3
(flet ((foo (a) (* foo a))) ; 5
(foo (* foo bar)))))) ; 4
2 ; 1
2 ; 2
2 ; 3
2 ; 4
2 ; 5
2370816
Here the symbol-macrolet knows which FOO to expand, and which not. There are five expansions in the code, which makes 2 printed five times. You can see that it works in nested code, too : it knows that some FOO are function names and those will not be expanded.
Whereas a MACROLET knows, where an operator needs to be expanded:
CL-USER 38 > (LET* ((FOO 10) (BAR (+ FOO 32)))
(macrolet ((foo (a) `(print ,a)))
(* foo bar foo bar (foo bar) ; 1
(flet ((bar (a) (foo a))) ; 2
(bar (* foo bar))))))
42 ; 1
420 ; 2
3111696000