Previous section: 14. Modules

Dylan reference manual -- Overview

Overview

A module establishes a mapping from variable names to variables (memory locations containing values). It does this in one of two ways: a variable can be owned by the module, or the module may import variables exported by another module by using the other module. Modules export variables to make them accessible to other modules. Only exported variables can be imported by other modules.

Within a given module, a variable name refers to at most one variable. It is an error to create or import two or more different variables with the same name in a single module. If a name does refer to a variable, the variable is said to be accessible from the module. Each variable is owned by exactly one module, but it can be accessible from many modules.

Owned variables are created by a create clause in a define module and in some cases by definitions associated with a module.

Dylan includes two kinds of definitions. Explicit definitions are created by define constant, define variable, define generic, and the class name in define class. Implicit definitions are created by define method and the slot specifications of define class.

Definitions are used both to create variables and to provide values for variables. An explicit definition performed on a variable which was not imported creates an owned variable and provides a value for it. An explicit definition performed on a variable which was imported just provides a value for the variable. An implicit definition has the same behavior, but only if there is no explicit definition for the variable. (If there is an explicit definition for the variable, then the implicit definition does not create the variable, nor does it provide the value for it.)

There must be exactly one explicit definition for each module variable, with the exception that the explicit definition can be left out if there are one or more implicit definitions. Any module variable whose value is a generic function can have any number of implicit definitions.

Next section: Programs, module declarations, and expressions