previous up next     contents index
Next: Creating Units Up: Programming Constructs Previous: Global Variable Namespaces

Units

 

 

MzScheme's units are used to organize a program into separately compilable and reusable components. A unit is similar to a procedure or a class in that it encapsulates unevaluated definitions and expressions. Unlike a procedure or class, a unit body cannot reference global variables directly (except the MzScheme primitives). Instead, a unit must explicitly import all external variables. A unit can also export variables for other units to import.gif A unit body can mutate variables using set!, but it cannot mutate imported variables.

When a unit is invoked, the expressions in the unit body are evaluated using new internal (including exported) variables. A unit can be invoked multiple times; each invocation creates new internal variables.





PLT