7
votes

Is there an easy way for me to load a submodule in the current file in racket-mode in emacs?

For example if I have the following file

#lang racket

(define (foo x)
  x)

(module+ sub
  (define (bar x y)
    x))

and I hit f5 in racket-mode to start the repl then foo is available but bar is not.

2

2 Answers

5
votes

You can combine dynamic-enter! and quote-module-path to do this.

Given a repl interaction for the code above that you posted:

> (require racket/enter syntax/location)
> (dynamic-enter! (quote-module-path sub))
> bar
#<procedure:bar>

Alternatively, you could use dynamic-require/expose (the expose part allows you require things that are not provided), as done here.

0
votes

It works the same way in DrRacket. You have to provide bar from the submodule, and require the submodule to use it. Try the following code:

#lang racket

(define (foo x)
  x)

(module+ sub
  (define (bar x y)
    x)
  (provide bar))

;; (bar 1 2) -- undefined

(require (submod "." sub))
(bar 1 2) ;; -- works here