The compound-unit form links several units into one new compound
unit. In the process, it matches imported variables in each sub-unit
either with exported variables of other sub-units or with its own
imported variables:
linkage is one of:
variable
(tag variable)
(tag variable )
exportage is one of:
variable
(internal-variable external-variable)
tag is:
identifier
(compound-unit
(import variable )
(link [tag (sub-unit-expr linkage )] )
(export (tag exportage ) ))
The three parts of a compound-unit expression have the following roles:
As in the export clause of the unit form, a re-exported variable can be renamed for external references using the (internal-variable external-variable) form. The internal-variable is used as the name exported by the sub-unit, and external-variable is the name visible outside the compound unit.
The evaluation of a compound-unit expression starts with the evaluation of the link clause's unit expressions (in sequence). For each sub-unit, the number of variables it imports must match the number of linkage specifications that are provided, and each linkage specification is matched to an imported variable by position. Each sub-unit must also export those variables that are specified by the link and export clauses. If, for any sub-unit, the number of imported variables does not agree with the number of linkages provided the exn:unit:arity exception is raised. If an expected exported variable is missing from a sub-unit for linking to another sub-unit, the exn:unit:import exception is raised. If an expected export variable is missing for re-export, the exn:unit:export exception is raised.
The invocation of a compound unit proceeds in two phases to invoke the sub-units. In the first phase, the compound unit resolves the imported variables of sub-units with the bindings provided for the compound unit's imports and new bindings created for sub-unit exports. In the second phase, the internal definitions and expressions of the sub-units are evaluated sequentially according to the order of the sub-units in the link clause. The result of invoking a compound unit is the result from the invocation of the last sub-unit.