[racket] About the always-renaming strategy in hygienic macro expansion
Hi,
I am trying to understand hygienic macro expansion by looking into
the algorithms, in the paper "Macros That Work" and "Syntactic
Abstraction in Scheme". Any of them may not exactly be what is
implemented in Racket but presumably the essential ideas are not
that different. Currently I encounter two problems in understanding:
1. If I understand these algorithms correctly, the lexical environment
of a macro definition is saved into a syntactic closure, so that free
variables inserted into the body of a macro will not be captured by any
binding construct in the context of a macro call. But I notice that
both expansion algorithms always rename bound variables of some core
binding constructs, like lambda. I see that if such a core binding
construct is inserted into the body of a macro, its bound variables
should be renamed to avoid capturing free variables from the context of
the macro call. But if such a core binding construct does not occur in
the body of a macro, its bound variables do not need be renamed. So I
wonder whether this always renaming strategy is simply a disregard of
distinguishing these two cases. If so, why do these algorithms do not
do the case distinction? Because it is too difficult or because it
would further complicate the algorithms?
2. Both algorithms also always rename pattern variables. I was told
that this is because a macro can insert another macro definition into
its body. Thus similar to the case of inserting a core binding construct,
the pattern variables should also be renamed. Although I can imagine
this, I think I would appreciate a good example that illustrates this
kind of capture.
Thank you for your attention.
Cheers,
Yi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140416/e0a15179/attachment.html>