On Sat, Dec 11, 2010 at 2:49 PM, YC <yinso.c...@gmail.com> wrote:

>
> On Sat, Dec 11, 2010 at 8:56 AM, Ryan Culpepper <ry...@ccs.neu.edu> wrote:
>
>>
>> If you are only supporting syntax-rules, then I recommend implementing the
>> algorithm from "Macros that Work" by Clinger and Rees. Hygienic macro
>> expansion does typically involve alpha-conversion---renaming lexical
>> variables to fresh names. The challenge, as you mention above, is in not
>> renaming too eagerly.
>
>
Looking at the paper, it occurred to me that one way to ensure that macro
expands to the correct binding is for the macro to carry the references to
the environment itself.

So for the example in the paper:

(let-syntax ((push (syntax-rules
                       ((push ?v ?x)
                        =>
                        (set! ?x (cons ?v ?x))))))
  (let ((pros (list "cheap" "fast"))
        (cons (list)))
    (push "unreliable" cons)))


The push macro already contains the bindings to set! and cons, so the later
shadowing of cons does not overwrite push's own copy of cons.  In that sense
a macro transformer's job is to merge its own environment along with the
call-site's environment.

The key to correctly implement macros is then to ensure that every macro
holds references to a environment at the point of its definition, so it can
then be used for merging during the expansion.

Is this a fair way of thinking about macro expansions?

Thanks,
yc
_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Reply via email to