On Thursday, September 26, 2019 at 3:37:43 PM UTC+2, Matthew Flatt wrote: 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 >
Thanks! This helps. I didn't know I was sailing into deep namespace waters. But another error has reared its head: when, in the REPL, I evaluate an expression in the foo language, I get standard-module-name-resolver: collection not found for module path: racket/match/gen-match collection: "racket/match" in collection directories: /tmp/build/dist/lib/plt/foo/collects/ context...: show-collection-err standard-module-name-resolver module-path-index-resolve5 module-path-index-resolve5 namespace-module-use->module+linklet-instances144 for-loop temp37_0 for-loop run-module-instance!125 for-loop loop thunk dynamic-wind loop expand-capturing-lifts loop racket/match is required in (sticking with your filenames) repl.rkt, as well as main.rkt and (not one of your filenames, but essentially just a source of macros that are in turn require'd in main.rkt) expander.rkt. I've added ++lib racket/match to raco exe, to no avail. If I copy all standard Racket collects into the distribution (which makes racket/match in some sense "available"), I get a similar error (possibly the same error, essentially, just with a bit of more information added): no module instance found: #<resolved-module-path:"/tmp/build/dist/lib/plt/foo/collects/racket/match/runtime.rkt"> 1 context...: do-error namespace->module-instance70 namespace-module-use->module+linklet-instances144 for-loop temp37_0 for-loop run-module-instance!125 for-loop loop thunk dynamic-wind loop expand-capturing-lifts loop /Users/pltbuild/build/plt-release-64/bundle/racket/collects/racket/repl.rkt:11:26 call-with-values FWIW, the "1" there way at the end of the error message presumably comes from what I'm trying to evaluate in the REPL: (assignment "a" 1) -- 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/578d1c50-1c95-43ac-8d0e-eb8a97503d7f%40googlegroups.com.