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

Importing and Exporting with Signatures

The unit/sig form creates a signed unit in the same way that the unit form creates a unit in the core system. The only difference between these forms is that signatures are used to specify the imports and exports of a signed unit.

In the primitive unit form, the import clause only determines the number of variables that will be imported when the unit is linked; there are no explicitly declared connections between the import variables. In contrast, a unit/sig form's import clause does not specify individual variables; instead, it specifies the signatures of units that will provide its imported variables, and all of the variables in each signature are imported. The ordered collection of signatures used for importing in a signed unit is the signed unit's import signature.

Although the collection of variables to be exported from a unit/sig expression is specified by a signature rather than an immediate sequence of variables,[footnote] variables are exported in a unit/sig form in the same way as in the unit form. The export signature of a signed unit is just the collection of names exported by the unit.

For example:

  (define-signature arithmetic^ (add subtract multiply divide power))
  (define-signature calculus^ (integrate))
  (define-signature graphics^ (add-pixel remove-pixel))
  (define-signature gravity^ (go))
  (define gravity@
    (unit/sig gravity^ (import arithmetic^ calculus^ graphics^)
      (define go (lambda (start-pos) ... subtract ... add-pixel ...))))

In this program fragment, the signed unit gravity@ imports a collection of arithmetic procedures, a collection of calculus procedures, and a collection of graphics procedures. The arithmetic collection will be provided through a signed unit that matches the arithmetic^ (export) signature, while the graphics collection will be provided through a signed unit that matches the graphics^ (export) signature. The gravity@ signed unit itself has the export signature gravity^.

Suppose that the procedures in graphics^ were named add and remove rather than add-pixel and remove-pixel. In this case, the gravity@ unit cannot import both the arithmetic^ and graphics^ signatures as above because the name add would be ambiguous in the unit body. To solve this naming problem, the imports of a signed unit can be distinguished by providing prefix tags:

  (define-signature graphics^ (add remove))
  (define gravity@
    (unit/sig gravity^ (import (a : arithmetic^) (c : calculus^) (g : graphics^))
      (define go (lambda (start-pos) ... a:subtract ... g:add ...))))

Details for the syntax of signatures are in section 7.3.1. The full unit/sig syntax is described in section 7.3.2.


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

PLT