[racket] metacircular interpreter: hygiene, lexical variable, and substitution ==> Re: recursive macro expanding order

From: YC (yinso.chen at gmail.com)
Date: Mon Dec 13 04:13:53 EST 2010

On Mon, Dec 13, 2010 at 12:13 AM, Ryan Culpepper <ryanc at ccs.neu.edu> wrote:

>
> Not quite. There might not be a single environment for the macro. This can
> happen if the macro definition itself (in particular, the macro's template)
> is introduced by some other macro. It is possible to have a macro definition
> contain two occurrences of the same symbol that refer to different bindings.
>

I think I understand the implication but are having hard time to think of
examples - is there an example handy that I can study somewhere?


> Beyond that, they should also be treated differently if used as binding
> occurrences. It is a common trick when limited to syntax-rules to construct
> a list of fresh names by recursively adding the same symbol to an
> accumulator list. Since each occurrence of the symbol is introduced by a
> different macro step, they're all different for the purpose of binding.
>
> (define-syntax with-fresh-names
>  (syntax-rules ()
>    [(with-fresh-names () names k k-arg)
>     (k names k-arg)]
>    [(with-fresh-names (thing . rest) names k k-arg)
>     (with-fresh-names rest (tmp . names) k k-arg)]))
>

Sorry I am having hard time understanding the meaning of the
with-fresh-names macro.


> You might decide that instead of each macro closing over its environment,
> each subterm of the template must close over its environment. That gets you
> to the *syntactic closures* macro system (also in SLIB). Long story short,
> it's effectively impossible to use. IIRC, the critical mistake of syntactic
> closures is assuming that the common case is that a macro knows the complete
> environment of its input subexpressions. That's true of the 'or' macro
> (hygiene test case #1), but it makes writing new binding forms difficult.
>
> If you take syntactic closures and relax the notion of "environment" to
> instead be "what seems to be the environment, given the expander's current
> state of knowledge" and adjusting the syntax representation and expander
> accordingly, you get the Dybvig-Hieb-Bruggeman algorithm ("the syntax-case
> algorithm").


So does the relaxing mean we only use call-site's environment instead of
definition-site's environment?  Or is there still an environment that the
macro definition should retain for expansion reference?

Thanks,
yc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101213/dd258d15/attachment.html>

Posted on the users mailing list.