Re: Namespaces Keith Wright 15 Aug 2005 04:20 UTC

> From: Andre van Tonder <xxxxxx@now.het.brown.edu>
>
>
> I have been wondering about the following technical issue:
>
>    (let ((x 1))
>      (let-syntax ((m (lambda (form)
>                        (let ((x 2))
>                          (syntax x)))))
>        (m)))
>
> There are two possibilities for what this should give, and I am
> trying to decide which would be the Right Thing.

     <crazy talk deleted>

> On the other hand, if there is a single namespace, we will get an
> "Identifier out of context error".  This is the answer that both
> Chez and MzScheme give.

They are both right, and I don't see how anyone can advocate
otherwise.  The whole point of hygienic macros is that the bindings
you think you see in the source code are the actual bindings.
The innermost binding occurrence of x is the one that binds.

RRRS requires that let-syntax bindings shadow let bindings,
in the sense that

   (let ((x 1))
      (let-syntax ((x (lambda(x) 12)))
         (x)))

is a call to the x macro, and so yields 12.  Why should a
let binding fail to shadow another let binding?

Perhaps modesty prevents you from saying it, but I can say
that the srfi-72 reference implementation gives:

    reference to undefined identifier: @x_799

presumably because it correctly renames x to match the innermost
binding so that the example expands to

    (let ((x 1)) @x_799)

Why would this be a problem?  If you want the outermost x then
use a different name for the innermost, just like you would if
the macro were not there at all.

--
     -- Keith Wright

Programmer in Chief, Free Computer Shop
 ---  Food, Shelter, Source code.  ---