[plt-scheme] Shadowing syntax at the top

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Dec 7 18:55:27 EST 2006

On Dec  8, Matthew Flatt wrote:
> 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.

Swindle deals with this by expanding a toplevel define to something

  (define foo (void))
  (set! foo <expr>)

which, perhaps, is a less surprising behavior?

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

Posted on the users mailing list.