Next: Restricting Signatures Up: Units with Signatures Overview Previous: Importing and Exporting with

## Linking with Signatures

The `compound-unit/sig` form links signed units into a signed compound unit in the same way that the `compound-unit` form links primitive units. In the `compound-unit/sig` form, signatures are used for importing just as in `unit/sig` (except that all import signatures must have a tag), but the use of signatures for linking and exporting is more complex.

Within a `compound-unit/sig` expression, each unit to be linked is represented by a tag. Each tag is followed by a signature and an expression. A tag's expression evaluates (at link-time) to a signed unit for linking. The export signature of this unit must satisfy the tag's signature. ``Satisfy'' does not mean ``match exactly''; satisfaction requires that the unit exports at least the variables specified in the tag's signature, but the unit may actually export additional variables. Those additional variables are ignored for linking and are effectively hidden by the compound unit.

To specify the compound unit's linkage, an entire unit is provided (via its tag) for each import of each linked unit. The number of units provided by a linkage must match the number of signatures imported by the linked unit, and the tag signature for each provided unit must match (exactly) the corresponding imported signature.

The following example shows the linking of an arithmetic unit, a calculus unit, a graphics unit, and a gravity modeling unit:

      (define-signature arithmetic^ (add subtract multiply divide power))
      (define-signature calculus^ (integrate))
      (define-signature graphics^ (add-pixel remove-pixel))
      (define-signature gravity^ (go))
      (define arithmetic@ (unit/sig arithmetic^ (import) ...))
      (define calculus@ (unit/sig calculus^ (import arithmetic^) ...))
      (define graphics@ (unit/sig graphics^ (import) ...))
      (define gravity@ (unit/sig gravity^ (import arithmetic^ calculus^ graphics^) ...))
      (define model@
        (compound-unit/sig
          (import)
          (link (ARITHMETIC : arithmetic^ (arithmetic@))
                (CALCULUS : calculus^ (calculus@ ARITHMETIC)))
                (GRAPHICS : graphics^ (graphics@))
                (GRAVITY : gravity^ (gravity@ ARITHMETIC CALCULUS GRAPHICS)))
          (export (var (GRAVITY go)))))

In the `compound-unit/sig` expression for `model@`, all link-time signature checks succeed since, for example, `arithmetic@` does indeed implement `arithmetic^` and `gravity@` does indeed import units with the `arithmetic^`, `calculus^`, and `graphics^` signatures.

The export signature of a signed compound unit is implicitly specified by the `export` clause. In the above example, the `model@` compound unit exports a `go` variable, so its export signature is the same as `gravity^`. More forms for exporting are described in section 7.2.4.

Next: Restricting Signatures Up: Units with Signatures Overview Previous: Importing and Exporting with