Next: Core Units Up: PLT MzScheme: Language Manual Previous: Object Utilities

# Units

MzScheme's units are used to organize a program into separately compilable and reusable components. A unit resembles a procedure in that both are first-class values that are used for abstraction. While procedures abstract over values in expressions, units abstract over names in collections of definitions. Just as a procedure is invoked to evaluate its expressions given actual arguments for its formal parameters, a unit is invoked to evaluate its definitions given actual references for its imported variables. Unlike a procedure, however, a unit's imported variables can be partially linked with the exported variables of another unit prior to invocation. Linking merges multiple units together into a single compound unit. The compound unit itself imports variables that will be propagated to unresolved imported variables in the linked units, and re-exports some variables from the linked units for further linking.

MzScheme supports two layers of units. The core unit system comprises the `unit`, `compound-unit`, and `invoke-unit` syntactic forms. These forms implement the basic mechanics of units for separate compilation and linking. While the semantics of units is most easily understood via the core forms, they are too verbose for specifying the interconnections between units in a large program. Therefore, a system of units with signatures is provided on top of the core forms, comprising the `define-signature`, `unit/sig`, `compound-unit/sig`, and `invoke-unit/sig` syntactic forms.

The core system is described first in section 7.1. The signature system is roughly described in section 7.2, and then described in detail in section 7.3. Finally, gory details about mixing core and signed units are presented in section 7.4.

- Core Units
  - Creating Units
  - Invoking Units
  - Linking Units and Creating Compound Units
  - Unit Utilities
- Units with Signatures Overview
  - Importing and Exporting with Signatures
  - Linking with Signatures
  - Restricting Signatures
  - Embedded Units
- Units with Signatures
  - Signatures
    - Flattening Signatures
  - Signed Units
  - Signed Compound Units
  - Invoking Signed Units
- Mixing Core and Signed Units
  - Extracting a Primitive Unit from a Signed Unit
  - Adding a Signature to Primitive Units
  - Expanding Signed Unit Expressions