syntax-rules in Scheme are "hygienic" and "referentially transparent" and must preserve Scheme's lexical scoping. From my understanding, this means that during the macro expansion phase, the expander would need to know about lambda and define.
- The expander needs to know about
lambda. Suppose we have this code:
If the expander did not know about the(define x 1) ((lambda (x) x) 2)lambdaspecial form, it would consider the twoxs in(lambda (x) x)to be bound to thexin(define x 1), which is incorrect. - The expander needs to know about
define, so that it knows where (i.e. in which scope) a particular identifier is defined. In addition, suppose we have this code:
In order to correctly determine that both(define n 1) (define f (lambda (x y) (+ x y))) (define lambda f) (lambda n n)nin(lambda n n)refer to(define n 1), the expander has to understand that(define lambda f)has changed the meaning oflambda(and therefore the expander has to stop using special rules for handlinglmabdain this scope).
What other special forms does the macro expander need to know about? Does it need to know about set!?