[previous] [up] [next]     [contents] [index]
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, invoke-unit, and invoke-open-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, invoke-unit/sig, and invoke-open-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.





PLT