Next: Invoking Signed Units Up: Units with Signatures Previous: Signed Units

## Signed Compound Units

The `compound-unit/sig` form links multiple signed units into a new signed compound unit: ``

      (compound-unit/sig
        (import (tag : signature)   )
        (link (tag : signature (expr linkage   ))   )
        (export export-element   ))

      linkage is one of:
         unit-path

      unit-path is one of:
         simple-unit-path
         (simple-unit-path : signature)

      simple-unit-path is one of:
         tag
         (tag identifier   )

      export-element is one of:
         (var (simple-unit-path variable))
         (var (simple-unit-path variable) external-variable)
         (open unit-path)
         (unit unit-path)
         (unit unit-path variable)
      tag is:
         identifier

The `import` clause is similar to the `import` clause of a `unit/sig` expression, except that all imported signatures must be given a tag identifier.

The `link` clause of a `compound-unit/sig` expression is different from the `link` clause of a `compound-unit` expression in two important aspects:

- Each sub-unit tag is followed by a signature. This signature corresponds to the export signature of the signed unit that will be associated with the tag.
- The linkage specification consists of references to entire signed units rather than to individual variables that are exported by units. A referencing unit-path has one of four forms:

  - The tag form references an imported unit or another sub-unit.
  - The `(tag : signature)` form references an imported unit or another sub-unit, and then restricts the effective signature of the referenced unit to signature.
  - The `(tag identifier )` references an embedded unit within a signed compound unit. The signature for the tag unit must contain a sub-signature that corresponds to the embedded unit, where the sub-signature's name is the initial identifier. Additional identifiers trace a path into nested sub-signatures to a final embedded unit. The degenerate `(tag)` form is equivalent to tag.
  - The `((tag identifier ) : signature)` form is like the `(tag identifier )` form except the effective signature of the referenced unit is restricted to signature.

The `export` clause determines which variables in the sub-units are re-exported and implicitly determines the export signature of the new compound unit. A signed compound unit can export both individual variables and entire signed units. When an entire signed unit is exported, it becomes an embedded unit of the resulting compound unit.

There are five different forms for specifying exports:

- The `(var (unit-path variable))` form exports variable from the unit referenced by unit-path. The export signature for the signed compound unit includes a variable element.
- The `(var (unit-path variable) external-variable)` form exports variable from the unit referenced by unit-path. The export signature for the signed compound unit includes an external-variable element.
- The `(open unit-path)` form exports variables and embedded units from the referenced unit. The collection of variables that are actually exported depends on the effective signature of the referenced unit:
  - If unit-path includes a signature restriction, then only elements from the restricting signature are exported.
  - Otherwise, if the referenced unit is an embedded unit, then only the elements from the associated sub-signature are exported.
  - Otherwise, unit-path is just tag; in this case, only elements from the signature associated with the tag are exported.

  In all cases, the export signature for the signed compound unit includes a copy of each element from the effective signature.
- The `(unit unit-path)` form exports the referenced unit as an embedded unit. The export signature for the signed compound unit includes a sub-signature corresponding to the effective signature from unit-path. The name of the sub-signature in the compound unit's export signature depends on unit-path:
  - If unit-path refers to a tagged import or a sub-unit, then the tag is used for the sub-signature name.
  - Otherwise, the referenced sub-unit was an embedded unit, and the original name for the associated sub-signature is re-used for the export signature's sub-signature.

- The `(unit unit-path identifier)` form exports an embedded unit like `(unit unit-path)` form, but identifier is used for the name of the sub-signature in the compound unit's export signature.

The collection of names exported by a compound unit must form a legal signature. This means that all exported names must be distinct.

Run-time checks insure that all `link` clause exprs evaluate to a signed unit, and that all linkages match according to the specified signatures:

- If an expr evaluates to anything other than a signed unit, the `exn:unit` exception is raised.
- If the export signature for a signed unit does not satisfy the signature specified with its tag, the `exn:unit:signature` exception is raised.
- If the number of units specified in a linkage does not match the number imported by a linking unit, the `exn:unit` exception is raised.
- If the (effective) signature of a provided unit does not match the corresponding import signature, then the `exn:unit` exception is raised.

Next: Invoking Signed Units Up: Units with Signatures Previous: Signed Units