Added clarifying notes emphasizing that dynamic-require
is a procedure so
giving plain s-exps like you would for `require` is unlikely to work as expected. Need use something that evaluates to the appropriate s-exp you want. Added more examples of different `dynamic-require` uses.
This commit is contained in:
parent
4e10ed0518
commit
5d1371cb73
|
@ -476,6 +476,11 @@ Return @racket[#t] if @racket[compiled-module-code] represents a
|
||||||
[fail-thunk (-> any) (lambda () ....)])
|
[fail-thunk (-> any) (lambda () ....)])
|
||||||
(or/c void? any/c)]{
|
(or/c void? any/c)]{
|
||||||
|
|
||||||
|
@margin-note{Because @racket[dynamic-require] is a procedure, giving a plain S-expression for
|
||||||
|
@racket[mod] the same way as you would for a @racket[require] expression likely won't give you
|
||||||
|
expected results. What you need instead is something that evaluates to an S-expression; using
|
||||||
|
@racket[quote] is one way to do it.}
|
||||||
|
|
||||||
Dynamically @tech{instantiates} the module specified by @racket[mod]
|
Dynamically @tech{instantiates} the module specified by @racket[mod]
|
||||||
in the current namespace's registry at the namespace's @tech{base
|
in the current namespace's registry at the namespace's @tech{base
|
||||||
phase}, if it is not yet @tech{instantiate}d. The current @tech{module
|
phase}, if it is not yet @tech{instantiate}d. The current @tech{module
|
||||||
|
@ -494,6 +499,11 @@ above the @tech{base phase}.
|
||||||
(dynamic-require ''a #f)
|
(dynamic-require ''a #f)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@margin-note{The double quoted @racket[''a] evaluates to the @racket[root-module-path] @racket['a]
|
||||||
|
(see the grammar for @racket[require]). Using @racket['a] or @racket[a] for @racket[mod] won't work
|
||||||
|
because the former evaluates to @racket[root-module-path] @racket[a] which fails since the example is
|
||||||
|
not a module installed in a collection, the latter is an undefined variable.}
|
||||||
|
|
||||||
When @racket[provided] is a symbol, the value of the module's export
|
When @racket[provided] is a symbol, the value of the module's export
|
||||||
with the given name is returned, and still the module is not
|
with the given name is returned, and still the module is not
|
||||||
@tech{visit}ed or made @tech{available} in higher phases.
|
@tech{visit}ed or made @tech{available} in higher phases.
|
||||||
|
@ -535,6 +545,31 @@ If @racket[provided] is @|void-const|, then the module is
|
||||||
@tech{visit}ed but not @tech{instantiate}d (see @secref["mod-parse"]),
|
@tech{visit}ed but not @tech{instantiate}d (see @secref["mod-parse"]),
|
||||||
and the result is @|void-const|.}
|
and the result is @|void-const|.}
|
||||||
|
|
||||||
|
More examples using different @racket[module-path] grammar expressions are given below:
|
||||||
|
|
||||||
|
@examples[#:eval mod-eval
|
||||||
|
(dynamic-require 'racket/base #f)
|
||||||
|
]
|
||||||
|
|
||||||
|
@examples[#:eval mod-eval
|
||||||
|
(dynamic-require (list 'lib "racket/base") #f)
|
||||||
|
]
|
||||||
|
|
||||||
|
@examples[#:eval mod-eval
|
||||||
|
(module a racket/base
|
||||||
|
(module b racket/base
|
||||||
|
(provide inner-dessert)
|
||||||
|
(define inner-dessert "tiramisu")))
|
||||||
|
(dynamic-require '(submod 'a b) 'inner-dessert)
|
||||||
|
]
|
||||||
|
|
||||||
|
The last line in the above example could instead have been written as
|
||||||
|
|
||||||
|
@examples[#:eval mod-eval
|
||||||
|
(dynamic-require ((lambda () (list 'submod ''a 'b))) 'inner-dessert)
|
||||||
|
]
|
||||||
|
|
||||||
|
which is equivalent.
|
||||||
|
|
||||||
@defproc[(dynamic-require-for-syntax [mod module-path?]
|
@defproc[(dynamic-require-for-syntax [mod module-path?]
|
||||||
[provided (or/c symbol? #f)]
|
[provided (or/c symbol? #f)]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user