Import declarations

An import declaration takes the following form:

(import {import-set} ...)

An import declaration provides a way to import identifiers exported by a library. Each import set names a set of bindings from a library and possibly specifies local names for the imported bindings. It takes one of the following forms:

  • library name
  • (only {import set} {identifier} ...)
  • (except {import set} {identifier} ...)
  • (prefix {import set} {identifier})
  • (rename {import set} ({identifier1} {identifier2}) ...)

In the first form, all of the identifiers in the named library's export clauses are imported with the same names (or the exported names if exported with rename). The additional import set forms modify this set as follows:

  • only produces a subset of the given import set including only the listed identifiers (after any renaming). It is an error if any of the listed identifiers are not found in the original set.
  • except produces a subset of the given import set, excluding the listed identifiers (after any renaming). It is an error if any of the listed identifiers are not found in the original set.
  • rename modifies the given import set, replacing each instance of identifier1 with identifier2. It is an error if any of the listed identifier1's are not found in the original set.
  • prefix automatically renames all identifiers in the given import set, prefixing each with the specified identifier.

In a program or library declaration, it is an error to import the same identifier more than once with different bindings, or to redefine or mutate an imported binding with a definition or with set!, or to refer to an identifier before it is imported. However, a REPL should permit these actions.

husk-scheme online documentation rev 3.19.3 (2016.07.10)