[plt-scheme] Bug(?) with shadowing syntactic keywords

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Nov 11 12:06:58 EST 2005

At Fri, 11 Nov 2005 11:46:34 -0500, David Van Horn wrote:
> I believe the following is a bug.  When run at the top level the result
> is 0, but I would expect the program to diverge.
> (define-syntax f
>   (syntax-rules ()
>     ((f) 0)))
> (define (f) (f))
> (f)

This is the intended behavior. The definition is compiled before it is
evaluated, and `f' remains bound to the macro while the definition is

It might make sense for the compiler to notice that it's compiling a
top-level definition, and then adjust bindings for the defined named
while compiling the rest of the expression. But this breaks down for
mutually recursive top-level definitions. If the compiler looks for
multiple definitions in a top-level `begin' to handle mutually
recursive definitions, then a top-level `begin' isn't the same as
splicing a top-level `begin' body into the top level, and that causes
problems elsewhere. The top level is just hopeless.


Posted on the users mailing list.