[racket] DrRacket and Modules

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Mon Aug 15 00:06:00 EDT 2011

The DrRacket module language does a few steps in between running the
code in the definitions window and giving you a prompt at the
interactions window.  The first is that it requires your module.  The
second is that it uses that module to construct a top-level namespace.
 The end result is that you can see everything from inside the module,
and you can use top-level defines to change their values.  This is a
feature of top-level (i.e., interactions window) evaluation, not

If you want to see the behavior from the documentation, add "#lang
racket/load" as the top line of your file.  Then the modules you write
below it will not be required, and you will be able to manipulate them

Carl Eastlund

On Mon, Aug 15, 2011 at 12:02 AM, Harry Spier <harryspier at hotmail.com> wrote:
> When I run the following code in DrRacket it behaves somewhat differently
> than the documentation says a module should.
> (module m racket
>   (define x 10)
>   (define cons 1))
> The Racket reference says:
> ---------------------------------------------------------------------
> One difference between a module and a top-level definition is that a module
> can be declared without instantiating its module-level definitions.
> Evaluation of a require instantiates (i.e., triggers the instantiation of) a
> declared module, which creates variables that correspond to its module-level
> definitions.
> For example, given the module declaration
> (module m racket
>   (define x 10))
> the evaluation of (require 'm) creates the variable x and installs 10 as its
> value. This x is unrelated to any top-level definition of x.
> --------------------------------------------------------------------------
> But when I run the above code, the interactions window shows that x is
> defined as 10 even though I don't execute a require statement.
> Also the Racket Guide says:
> ----------------------------------------------------
> A module-level define can bind only identifiers that are not already bound
> within the module. For example, (define cons 1) is a syntax error in a
> racket module, since cons is provided by racket. A local define or other
> binding forms, however, can give a new local binding for an identifier that
> already has a binding; such a binding shadows the existing binding.
> ------------------------------------------------------
> But DrRacket doesn't give an error for (define cons 1) and the interactions
> window shows cons has been redefined as 1.
> Could someone explain why the behavior in DrRacket differs in these cases
> from the documentation.
> Thanks in advance,
> Harry Spier
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Posted on the users mailing list.