Racket REPL and submodules

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

For example, if I have the following file

#lang racket (define (foo x) x) (module+ sub (define (bar xy) x)) 

and I hit f5 in racket mode to run repl, then foo is available, but bar not.

+6
source share
2 answers

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

Given the interaction with the replacement for the above code:

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

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

+4
source

It works similarly in DrRacket. You must provide bar from a submodule, and require is a submodule to use it. Try the following code:

 #lang racket (define (foo x) x) (module+ sub (define (bar xy) x) (provide bar)) ;; (bar 1 2) -- undefined (require (submod "." sub)) (bar 1 2) ;; -- works here 
0
source

All Articles