[racket] Different behavior when using (#%require scheme/base)

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Mar 8 07:56:16 EST 2011

[File under "The top level is hopeless". A web search on that phrase
 should turn up related explanations, questions, and answers.]

At Tue, 8 Mar 2011 07:50:16 -0500, Sam Tobin-Hochstadt wrote:
> `scheme/base' provides a binding called `exp', which requires 2
> arguments.  When the compiler expands your definition, it looks at the
> variable reference in the body of the function *before* it binds your
> new `exp' definition.  Therefore, it uses the `exp' that it has in
> scope at that time -- the one from `scheme/base'.
> 
> This is an instance of a general problem with compilation and
> expansion at the top-level, and one of the many reasons why it's
> better to write programs in modules.
> 
> On Tue, Mar 8, 2011 at 7:37 AM, Yaron Gonen <yaron.gonen at gmail.com> wrote:
> > Hi,
> > (I'm using Dr Scheme version 4.2.2, with language R5RS, and the "Disallow
> > redefining" is not checked.)
> >
> > The following code works perfectly:
> > (define exp
> >   (lambda (b e)
> >     (if (= e 0) 1
> >         (* b (exp b (- e 1))))))
> > (exp 2 5)
> >
> > However, when I include the line (#%require scheme/base), I get an error:
> > exp: expects 1 argument, given 2: 2 4
> >
> > How is that possible?
> >
> > Many thanks,
> > Yaron
> >
> > _________________________________________________
> >  For list-related administrative tasks:
> >  http://lists.racket-lang.org/listinfo/users
> >
> 
> 
> 
> -- 
> sam th
> samth at ccs.neu.edu
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users



Posted on the users mailing list.