I know I can use (read-eval-print-loop)
, but by default it has no #%top-interaction
or #%app
or anything.
I would also like to be able to augment it with specific bindings.
I know I can use (read-eval-print-loop)
, but by default it has no #%top-interaction
or #%app
or anything.
I would also like to be able to augment it with specific bindings.
You need to set the current-namespace
: by default, this parameter is unconnected to any code.
The template is
(parameterize ([current-namespace N])
(read-eval-print-loop))
A reasonable value for N
is (make-base-namespace)
, which is like using racket/base
for all initial bindings.
If you want to augment bindings, you can
(define-namespace-anchor this-module)
and use (namespace-anchor->namespace this-module)
as N
. Then any bindings in the current module (including those provided by require
s) are available in the REPL.
module->namespace
is another reasonable value. It gives you bindings inside any arbitrary module. The REPL in tools like Dr Racket, xrepl, and Racket Mode is, as a starting point, (parameterize ([current-namespace (module->namespace mod-path)]) (read-eval-print-loop))
.