[plt-scheme] Shadowing syntax at the top

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Dec 7 17:18:22 EST 2006

At Thu, 07 Dec 2006 16:10:47 -0500, David Van Horn wrote:
> Welcome to DrScheme, version 360-svn20nov2006.
> Language: Standard (R5RS).
>  > (define (let) (let))
> let: bad syntax in: (let)
> 
> I'm pretty sure this should loop, and not be a syntax error.  Is this 
> intended?

Yes, this is as intended.

The new binding for `let' does not exist until the definition is
evaluated, so the old definition of `let' applies when the RHS of the
definition is expanded.

It's possible for the expander to notice that `let' is being defined,
and thus expand the RHS of the definition with the special assumption
that `let' is a variable instead of a syntactic keyword. But then
consider a pair of definitions grouped with `begin':

 (begin 
  (define (other) (let)) 
  (define (let) 10))

If you want this to work, then `begin' has to look ahead to other
definitions before expanding a definition. That's certainly possible,
but then it's no longer the case that wrapping a sequence of top-level
forms with `begin' is the same as splicing the forms into the top
level. So, the choice is to make this work or keep the splicing nature
of `begin'. If you don't make it work but change the sngle-definition
case, then it seems inconsistent to me. If you drop the splicing nature
of `begin' then other dominoes start to fall over, such as the handling
of `load' in a `begin' sequence.

In short, the top level is hopeless. I'm not entirely happy with the
current set of compromises, but I doubt that it's worth trying to
change them.

Matthew



Posted on the users mailing list.