<br><div class="gmail_quote">On Mon, Dec 13, 2010 at 12:13 AM, Ryan Culpepper <span dir="ltr"><<a href="mailto:ryanc@ccs.neu.edu" target="_blank">ryanc@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div><br></div></div>
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.<br>
</blockquote><div><br></div><div>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? </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>
<br>
(define-syntax with-fresh-names<br>
(syntax-rules ()<br>
[(with-fresh-names () names k k-arg)<br>
(k names k-arg)]<br>
[(with-fresh-names (thing . rest) names k k-arg)<br>
(with-fresh-names rest (tmp . names) k k-arg)]))<br></blockquote><div><br></div><div>Sorry I am having hard time understanding the meaning of the with-fresh-names macro. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>
<br>
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").</blockquote>
<div><br></div><div>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? </div>
<div><br></div><div>Thanks, </div><div>yc</div><div><br></div><div><br></div></div>