[racket] submodule paths and DrRacket

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Sun Nov 18 21:31:49 EST 2012

On 2012-11-18 21:10:25 -0500, Harry Spier wrote:
>    Case 1 as follows works in the DrRacket Definitions window but doesn't
>    work in the Interactions window
>
>    #lang racket
>
>    (module m racket
>      (provide color)
>      (define color "blue"))
>    (module n racket
>      (require (submod ".." m))
>      (printf "my favorite color is ~a\n" color))

In the definitions window, the use of #lang implicitly wraps the entire
contents of the window in a module. This allows the use of relative
submodule references to module `m`.

In the interactions window, you are defining top-level modules instead.
You can get the same behavior if you wrap both `m` and `n` in another
module in the interactions window:

  (module around racket
    ;; put m and n here
    ...)

>    Case 2 as follows works in the DrRacket Interactions window but doesn't
>    work in the Definitions window
>
>    > (module m racket
>        (provide color)
>        (define color "blue"))
>      (module n racket
>        (require 'm)
>        (printf "my favorite color is ~a\n" color))
>      (require 'n)

This time, it works in the interactions window because they are both
top-level modules. Within a module, you can't refer to the parent's
submodules directly with a quoted name.

>    Also is there a way to have
>
>     #lang racket
>
>     (module m racket
>       (provide color)
>       (define color "blue"))
>
>    in the definitions window but the following in the interactions window
>
>    >(module n racket
>       (require SOME SUBMODULE PATH TO m)
>       (printf "my favorite color is ~a\n" color))
>     (require 'n)

Yes. Suppose the first snippet is defined in "foo.rkt". Then you can
just have (require (submod "foo.rkt" m)) if you're in the right
directory.

Cheers,
Asumu

Posted on the users mailing list.