[previous] [up] [next]     [contents] [index]
Next: Examples Up: Core Units Previous: Core Units

Creating Units

The unit form creates a unit:

  (unit
     (import variable  tex2html_wrap_inline12550 )
     (export exportage  tex2html_wrap_inline12550 )
     unit-body-expr
      tex2html_wrap_inline12550 )

exportage is one of: variable (internal-variable external-variable)

The variables in the import clause are bound within the unit-body-expr expressions. The variables for exportages in the export clause must be defined in the unit-body-exprs as described below; additional private variables can be defined as well. The imported variables cannot occur on the left-hand side of an assignment (i.e., a set! expression).

The first exportage form exports the binding defined as variable in the unit body using the external name variable. The second form exports the binding defined as internal-variable using the external name external-variable. The external variables from an export clause must be distinct.

Each exported variable or internal-variable must be defined in a define-values expression as a unit-body-expr.[footnote] All identifers defined by the unit-body-exprs together with the variables from the import clause must be distinct.

A unit-body-expr cannot reference a variable in the global namespace. However, MzScheme's built-in variables are implicitly imported into all units. Lexical bindings of built-in identifers can override the built-in value, but bindings in the top-level environment cannot. For example, assuming the variable cons is not lexically bound, the cons in a unit-body-expr denotes the expected Scheme pairing primitive, regardless of the current binding of cons in the top-level environment.



PLT