On this page:
import
open
module

9 Modules and Imports🔗ℹ

A Shplait program that starts with #lang shplait is a module, and its definitions are all implicitly exported for use by other modules. Use import in a module to import definitions from other modules. The module form adds to a submodule, which is nested inside another module.

definition

import:

  import_spec

  ...

 

import_spec

 = 

module_path

 | 

open:

  module_path

  ...

 

module_path

 = 

id

 | 

id / module_path

 | 

lib(module_string)

 | 

file(path_string)

 

import

open: module_path; ...

The import form acts like a definition for all of the exports of another module, making them available in the current definition context. Typically, import is used in an immediate module body, but it also can be used in a nested form, such as a block form.

If open is not used, then the last component of module_path (not counting a file suffix, if any), is used to prefix all of the imported names. Use the prefix, then ., then a name exported from the module to use that name. If open is used for the module, then its exported names can be used directly, without a prefix.

declaration

module id:

  defn_or_expr

  ...

 

defn_or_expr

 = 

defn

 | 

expr

Adds to the submodule name id within the enclosing module. Typically, id is test, which adds to a submodule that DrRacket automatically runs after the enclosing module, so that tests within the submodule can run after all definitions are ready. The submodule name main is also special; it is run when the enclosing module is run as a main program, but not when the enclosing module is used as imported into another module.