Updated docs to add examples for module->* functions.

This commit is contained in:
Leif Andersen 2016-05-19 19:00:20 -04:00
parent afec68f639
commit fe03198211
2 changed files with 53 additions and 17 deletions

View File

@ -523,12 +523,13 @@ modules can define the name. That is, a @deftech{module-level
variable} is like a @tech{top-level variable} from the perspective of variable} is like a @tech{top-level variable} from the perspective of
evaluation. evaluation.
One difference between a module and a top-level definition is that a One difference between a module and a top-level definition
module can be declared without instantiating its module-level is that a module can be @deftech[#:key "declare"]{declared}
definitions. Evaluation of a @racket[require] @deftech{instantiates} without instantiating its module-level definitions.
(i.e., triggers the @deftech{instantiation} of) a declared module, Evaluation of a @racket[require] @deftech{instantiates}
which creates variables that correspond to its module-level (i.e., triggers the @deftech{instantiation} of) a declared
definitions. module, which creates variables that correspond to its
module-level definitions.
For example, given the module declaration For example, given the module declaration

View File

@ -573,14 +573,19 @@ because the root module does not exist.}
Returns information intended to reflect the ``language'' of the Returns information intended to reflect the ``language'' of the
implementation of @racket[mod]. If @racket[mod] is a implementation of @racket[mod]. If @racket[mod] is a
@tech{resolved module path} or @racket[load?] is @racket[#f], the @tech{resolved module path} or @racket[load?] is @racket[#f], the
module named by @racket[mod] must be declared (but not necessarily module named by @racket[mod] must be @tech{declare}d (but not necessarily
@tech{instantiate}d or @tech{visit}ed) in the current namespace; @tech{instantiate}d or @tech{visit}ed) in the current namespace;
otherwise, @racket[mod] may be loaded (as for @racket[dynamic-require] otherwise, @racket[mod] may be loaded (as for @racket[dynamic-require]
and other functions). The information returned by and other functions). The information returned by
@racket[module->language-info] is the same as would have been returned @racket[module->language-info] is the same as would have been returned
by @racket[module-compiled-language-info] applied to the module's by @racket[module-compiled-language-info] applied to the module's
implementation as compiled code.} implementation as compiled code.
A module can be @tech{declare}d by using @racket[dynamic-require].
@examples[#:eval mod-eval
(dynamic-require 'racket/dict (void))
(module->language-info 'racket/dict)]}
@defproc[(module->imports @defproc[(module->imports
[mod (or/c module-path? module-path-index? [mod (or/c module-path? module-path-index?
@ -588,9 +593,19 @@ implementation as compiled code.}
(listof (cons/c (or/c exact-integer? #f) (listof (cons/c (or/c exact-integer? #f)
(listof module-path-index?)))]{ (listof module-path-index?)))]{
Like @racket[module-compiled-imports], but produces the imports of Like @racket[module-compiled-imports], but produces the
@racket[mod], which must be declared (but not necessarily imports of @racket[mod], which must be @tech{declare}d (but
@tech{instantiate}d or @tech{visit}ed) in the current namespace.} not necessarily @tech{instantiate}d or @tech{visit}ed) in
the current namespace. See @racket[module->language-info] for
an example of declaring an existing module.
@examples[#:eval mod-eval
(module banana racket/base
(require (only-in racket/math pi))
(provide peel)
(define peel pi)
(define bush (* 2 pi)))
(module->imports ''banana)]}
@defproc[(module->exports @defproc[(module->exports
@ -598,17 +613,37 @@ Like @racket[module-compiled-imports], but produces the imports of
(values (listof (cons/c (or/c exact-integer? #f) list?)) (values (listof (cons/c (or/c exact-integer? #f) list?))
(listof (cons/c (or/c exact-integer? #f) list?)))]{ (listof (cons/c (or/c exact-integer? #f) list?)))]{
Like @racket[module-compiled-exports], but produces the exports of Like @racket[module-compiled-exports], but produces the
@racket[mod], which must be declared (but not necessarily exports of @racket[mod], which must be @tech{declare}d (but
@tech{instantiate}d or @tech{visit}ed) in the current namespace.} not necessarily @tech{instantiate}d or @tech{visit}ed) in
the current namespace. See @racket[module->language-info] for
an example of declaring an existing module.
@examples[#:eval mod-eval
(module banana racket/base
(require (only-in racket/math pi))
(provide peel)
(define peel pi)
(define bush (* 2 pi)))
(module->exports ''banana)]}
@defproc[(module->indirect-exports @defproc[(module->indirect-exports
[mod (or/c module-path? resolved-module-path?)]) [mod (or/c module-path? resolved-module-path?)])
(listof (cons/c exact-integer? (listof symbol?)))]{ (listof (cons/c exact-integer? (listof symbol?)))]{
Like @racket[module-compiled-exports], but produces the exports of Like @racket[module-compiled-exports], but produces the
@racket[mod], which must be declared (but not necessarily exports of @racket[mod], which must be @tech{declare}d (but
@tech{instantiate}d or @tech{visit}ed) in the current namespace. not necessarily @tech{instantiate}d or @tech{visit}ed) in
the current namespace. See @racket[module->language-info] for
an example of declaring an existing module.
@examples[#:eval mod-eval
(module banana racket/base
(require (only-in racket/math pi))
(provide peel)
(define peel pi)
(define bush (* 2 pi)))
(module->indirect-exports ''banana)]
@history[#:added "6.5.0.5"]} @history[#:added "6.5.0.5"]}