3.18 Importing: require, require-for-syntax, require-for-template
(require require-spec ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In a top-level context, require instantiates modules (see Modules and Module-Level Variables). In a module context, require visits modules (see Module Phases). In both contexts, require introduces bindings into a namespace or a module (see Introducing Bindings). A require form in a expression context or internal-definition context is a syntax error.
A require-spec designates a particular set of identifiers to be bound in the importing context. Each identifier is mapped to a particular export of a particular module; the identifier to bind may be different from the symbolic name of the originally exported identifier.
module-path
Imports all exported bindings from the named module, using the export identifier as the local identifiers. (See below for information on module-path.)
(only require-spec id-maybe-renamed )
Like require-spec, but constrained to those exports for which the identifiers to bind match id-maybe-renamed: as id or as orig-id in [orig-id bind-id]. If the id of orig-id of any id-maybe-renamed is not in the set that require-spec describes, a syntax error is reported.
(except require-spec id )
Like require-spec, but omitting those exports for which ids are the identifiers to bind; if any id is not in the set that require-spec describes, a syntax error is reported.
(prefix require-spec prefix-id)
Like require-spec, but adjusting each identifier to be bound by prefixing it with prefix-id.
(rename require-spec [orig-id bind-id] )
Like require-spec, but replacing the identifier to bind orig-id with bind-id; if any orig-id is not in the set that require-spec describes, a syntax error is reported.
A module-path identifies a module, either through a concrete name in the form of an identifier, or through an indirect name that can trigger automatic loading of the module declaration. Except for the id case below, the actual resolution is up to the current module name resolver (see current-module-name-resolver), and the description below corresponds to the default module name resolver.
id
Refers to a module previously declared with the name id.
rel-string
A path relative to the containing source (as determined by current-load-relative-directory or current-directory). Regardless of the current platform, rel-string is always parsed as a Unix-format relative path: / is the path delimiter (multiple adjacent /s are treated as a single delimiter), .. accesses the parent directory, and . accesses the current directory. The path cannot be empty or contain a leading or trailing slash.
(lib rel-string)
Like the plain rel-string case, but rel-string must contain at least two path elements. All path elements up to the last one form a collection path, which is used to locate the relevant directory (not relative to the containing source), and the last path element refers to a file. See Libraries and Collections for more information.
(file string)
Similar to the plain rel-string case, but string is a path (possibly absolute) using the current platform’s path conventions.
(planet rel-string (user-string pkg-string vers ))
Specifies a library available via the PLaneT server.
No identifier can be bound multiple times by an import, unless all of the bindings refer to the same original definition in the same module. In a module context, an identifier can be either imported or defined for a given phase level, but not both.
(require-for-syntax require-spec ) |
Like require, but instantiates a module at phase 1 (see Modules and Module-Level Variables) in a top-level context or module context, and introduces bindings at phase level 1 (see Introducing Bindings and Module Phases).
(require-for-template require-spec ) |
Like require, but without instantiation (see Modules and Module-Level Variables) in a top-level context, and introduces bindings at phase level -1 (see Introducing Bindings and Module Phases).