[plt-scheme] repl and namespaces

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Feb 16 20:53:57 EST 2003

At Mon, 10 Feb 2003 08:32:40 -0500, Peter Santoro wrote:
> The following debug-repl works if I type in (exit) or 
> (quit), but doesn't recognize any of my modules' symbols during eval.  I 
> believe I have a namespace issue.
> (define (debug-repl)
>    (display "\ndebug> ")
>    (let ((expr (read)))
>      (cond ((or (equal? expr '(exit)) (equal? expr '(quit))) (newline))
>            (else (display (eval expr))(debug-repl)))))

If you want to set up a dedicated namespace with your module's
bindings, you probably want something like

 (paramterize ([current-namespace (make-namespace)])
   (namespace-require '<module path>)

where "<module path>" should be replaced with your module's path. The
above will create a new instance of your module (plus anything that it
requires) for the new namespace.

If you already have an instance of the module that you want to use,
it's a bit more involved:

  (define (make-namespace-with-my-module)
    (let ([orig (current-namespace)]
	  [mod-name ((current-module-name-resolver) '<module path> #f #f)]
	  [ns (make-namespace)])
      (parameterize ([current-namespace ns])
	(namespace-attach-module orig mod-name))

 (paramterize ([current-namespace (make-namespace-with-my-module)])

> 1) Are there better ways to write customized REPLs in mzscheme, perhaps 
> via (parameterize .... (read-eval-print-loop))?

Yes. You can set `current-eval', for example. Here's the general case:

  (parameterize ([current-prompt-read my-read] 
                 [current-eval my-eval] 
                 [current-print my-print]) 


Posted on the users mailing list.