[previous] [up] [next]     [index]
Next: Units with Signatures Up: Units with Signatures Overview Previous: Restricting Signatures

Embedded Units

Signed compound units can re-export variables from linked units in the same way that core compound units can re-export variables. The difference in this case is that the collection of variables that are re-exported determines an export signature for the compound unit. Using certain export forms, such as the open form instead of the var form (see section 7.3.3), makes it easier to export a number of variables at once, but these are simply shorthand notations.

Signed compound units can also export entire units as well as variables. Such an exported unit is an embedded unit of the compound unit. Extending the example from section 7.2.3, the entire gravity@ unit can be exported from model@ using the unit export form:

  (define model@
    (compound-unit/sig
      (import)
      (link (ARITHMETIC : arithmetic^ (arithmetic@))
            (CALCULUS : calculus^ (calculus@ (ARITHMETIC : simple-arithmetic^))))
            (GRAPHICS : graphics^ (graphics@))
            (GRAVITY : gravity^ (gravity@ ARITHMETIC GRAPHICS)))
      (export (unit GRAVITY))))

The export signature of model@ no longer matches gravity^. When a compound unit exports an embedded unit, the export signature of the compound unit has a sub-signature that corresponds to the full export signature of the embedded unit. The following signature, model^, is the export signature for the revised model@:

  (define-signature model^ ((unit GRAVITY : gravity^)))

The signature model^ matches the (implicit) export signature of model@ since it contains a sub-signature named GRAVITY--matching the tag used to export the gravity@ unit--that matches the export signature of gravity@.

The export form (unit GRAVITY) does not export any variable other than gravity@'s go, but the ``unitness'' of gravity@ is intact. The embedded GRAVITY unit is now available for linking when model@ is linked to other units.

For example:

  (define tester@ (unit/sig () (import gravity^) (go 0)))
  (define test-program@
    (compound-unit/sig
       (import)
       (link (MODEL : model^ (model@))
             (TESTER : () (tester@ (MODEL GRAVITY))))
       (export)))

The embedded GRAVITY unit is linked as an import into the tester@ unit by using the path (MODEL GRAVITY).



PLT