counterintuitive behavior of namespace-require

17 views
Skip to first unread message

Yongming Shen

unread,
Jan 6, 2020, 10:09:44 PM1/6/20
to Racket Users
Hi, I have encountered a counterintuitive behavior of namespace-require and wonder if it is a bug.
Basically, namespace-require behaves differently when the target namespace is passed by parameterizing current-namespace, compared to when the optional namespace parameter is used.

For example, this works:

(define ns (make-base-empty-namespace))
(parameterize ([current-namespace ns]) (namespace-require 'racket))

But this gives an error about unknown module:

(define ns (make-base-empty-namespace))
(namespace-require 'racket ns)

    require: unknown module
    module name: #<resolved-module-path:"/Applications/Racket v7.3/collects/racket/main.rkt">

Am I doing something wrong in the second case?

Thanks,
Yongming

Matthew Flatt

unread,
Jan 6, 2020, 10:28:21 PM1/6/20
to Yongming Shen, Racket Users
The problem is that `namespace-require` has to first resolve the
`racket` module path, and the module name resolver uses the current
namespace as determined by `current-namespace` --- which means that the
resolver loads the `racket` module into the wrong namespace.

I doubt that we can change that behavior without breaking something.
Probably this will need to be addressed with a documentation
improvement that discourages providing a namespace directly except in
limited cases.
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/45e0ee10-0ce0-42a9-997f-ad102e09
> 8ea4%40googlegroups.com.

Yongming Shen

unread,
Jan 6, 2020, 10:55:42 PM1/6/20
to Racket Users
I see, thanks for the explanation!
Reply all
Reply to author
Forward
0 new messages