The name `'restricted` is allowed as a shorthand in `require` because
`require` knows what module it's in. The `namespace-attach-module`
function does not try to infer a module context from the namespace
argument; it uses the namespace argument only for its registry. So, you
need to use the full name of the submodule.

The `quote-module-path` form expands to a full name using its syntactic
context (i.e., the enclsoing module's name), so

  (namespace-attach-module (namespace-anchor->namespace a)
                           (quote-module-path restricted)
                           ns)

is probably what you want.


At Fri, 16 Apr 2021 17:29:28 +0000, Sage Gerard wrote:
> Why does this raise "namespace-attach-module: module not declared (in
> the source namespace)"?
> 
> I expected that the `restricted` submodule would be both declared and
> instantiated by the time control reached `namespace-attach-module`.
> 
> (module anon racket/base
>    (module restricted racket/base
>      (provide #%app #%datum #%top hello)
>      (define (hello h) h))
>    (require 'restricted)
>    (define ns (make-empty-namespace))
>    (define-namespace-anchor a)
>    (namespace-attach-module (namespace-anchor->namespace a) ''restricted ns)
>    (displayln (eval '(hello "world") ns)))
> 
> --
> ~slg

-- 
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/20210416115117.107%40sirmail.smtps.cs.utah.edu.

Reply via email to