6.4 Imports: require
The require form imports from another module. A require form can appear within a module, in which case it introduces bindings from the specified module into importing module. A require form can also appear at the top level, in which case it both imports bindings and instantiates the specified module; that is, it evaluates the body definitions and expressions of the specified module, if they have not been evaluated already.
A single require can specify multiple imports at once:
(require require-spec ...)
Specifying multiple require-specs in a single require is essentially the same as using multiple requires, each with a single require-spec. The difference is minor, and confined to the top-level: a single require can import a given identifier at most once, whereas a separate require can replace the bindings of a previous require (both only at the top level, outside of a module).
The allowed shape of a require-spec is defined recursively:
In its simplest form, a require-spec is a module-path (as defined in the previous section, Module Paths). In this case, the bindings introduced by require are determined by provide declarations within each module referenced by each module-path.Examples:
(only-in require-spec id-maybe-renamed ...)
id-maybe-renamed = id | [orig-id bind-id]
An only-in form limits the set of bindings that would be introduced by a base require-spec. Also, only-in optionally renames each binding that is preserved: in a [orig-id bind-id] form, the orig-id refers to a binding implied by require-spec, and bind-id is the name that will be bound in the importing context instead of orig-id.Examples:
> (module m (lib "racket") (provide tastes-great? less-filling?) (define tastes-great? #t) (define less-filling? #t)) > (require (only-in 'm tastes-great?)) > tastes-great?
cannot reference undefined identifier
> (require (only-in 'm [less-filling? lite?])) > lite?
(prefix-in prefix-id require-spec)
This is a shorthand for renaming, where prefix-id is added to the front of each identifier specified by require-spec.
imports all bindings that m exports, except for the ghost binding, and with local names that are prefixed with m:.