[plt-scheme] What is the role of Syntax Transformers?

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Jun 28 21:55:34 EDT 2008

On Jun 28, Grant Rettke wrote:
> I read this article:
> 
> http://blog.plt-scheme.org/2008/02/dirty-looking-hygiene.html
> 
> And see that you can utilize syntax parameters in lieu of unhygienic
> macros.
> 
> Is that their goal? Where does this language feature fit?

Just like the title says -- it's only an illusion.  The fact is that
hygiene is not actually broken with syntax parameters -- the name *is*
grabbed globally and provided.  For example, assume that you have a
`loop' macro that needs to bind unhygienically `break'.  For example:

  (loop ... (when (= i 100) (break)))

With syntax parameters you do provide `break' -- it just happens to
raise a syntax error unless it's inside a `loop'.  Here are some
concrete example for things that will show the differences

  (let ([break void])
    (loop ... (when (= i 100) (break))))

An unhygienic macro will have `break' do the usual thing; but with
syntax parameters the `break' obeys lexical scope and will be bound to
`void'.  (And that's a good thing, since lexical scope still works.)

Another example is

  (require (rename-in "loop-macro.ss" [loop repeat] [break abort]))
  (repeat ... (when (= i 100) (abort)))

this does not work with unhygienic macro, but is perfectly fine with
syntax parameters.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.