At Tue, 24 Sep 2019 22:37:41 -0700 (PDT), Jesse Alama wrote: > This works for making a standalone executable that can exectute foo > programs specified on the command line, but doesn't work for a REPL. The > difficulty seems to be the `namespace-require` part of `run-repl`, defined > like this: > > ```` > (define (run-repl) > (parameterize ([current-namespace (make-base-empty-namespace)]) > (namespace-require 'foo/expander) > (read-eval-print-loop))) > ```` > > When I invoke the executable with no arguments, `run-repl` gets called. But > this leads to: > > ```` > standard-module-name-resolver: collection not found > for module path: racket/base/lang/reader > collection: "racket/base/lang" > ````
The problem is that `racket/base` is declared only in the original namespace. When you create a fresh namespace, then it gets a fresh registry, and `racket/base` is not in that registry. Really, that goes for `foo/expander`. It's not so much that you want to refer to `racket/base` as `foo/expander`. While `++lang foo` should make `foo/expander` be in the original namespace's registry (assuming that the `foo` language refers to it), it won't be in the fresh namespace's registry. The solution is to attach the module declaration from the original namespace to the new namespace. Here's an example to demonstrate, assuming that the "foo" directory is installed as a package. The `foo` language here supports just literals and addition. ;; ---------------------------------------- ;; foo/main.rkt #lang racket/base (provide #%app #%datum #%module-begin #%top-interaction +) (module reader syntax/module-reader foo) ;; ---------------------------------------- ;; repl.rkt #lang racket/base (require racket/cmdline ;; Ensure that `foo` is here to attach (only-in foo)) (command-line #:args ([file #f]) (cond [(not file) (define ns (make-base-empty-namespace)) (namespace-attach-module (current-namespace) 'foo ns) (current-namespace ns) (namespace-require 'foo) (read-eval-print-loop)] [else (dynamic-require file #f)])) ;; ---------------------------------------- ;; Command line raco exe ++lang foo repl.rkt raco dist repl-dist repl -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/5d8cbf24.1c69fb81.f4bd9.0e12SMTPIN_ADDED_MISSING%40gmr-mx.google.com.