previous up next     contents index
Next: Examples Up: Units Previous: Examples

Creating Compound Units

 

 

The  compound-unit form links multiple sub-units into a single new unit and matches imported variables in each sub-unit with exported variables of other sub-units:

 
   (compound-unit
      (import identifier  tex2html_wrap_inline8722 )
      (link [tag (sub-unit-expr imported-variable  tex2html_wrap_inline8722 )]  tex2html_wrap_inline8722 )
      (export (tag exported-identifier  tex2html_wrap_inline8722 )  tex2html_wrap_inline8722 )) 

Each sub-unit-expr in the with clause must evaluate to a unit value, otherwise the  exn:unit:non-unit exception is raised. Each sub-unit-expr is evaluated when the compound unit is created, but the sub-units are not invoked until the compound unit is invoked. When the compound unit is invoked, each of the sub-units will be invoked in the order that they are listed in the link clause.

Each unit value is associated with the corresponding tag, an identifier, within the rest of the compound-unit expression. Each tag must be unique.

The imported-variable clauses after a unit-expr expression specify the variables that are to be imported into the corresponding sub-unit. Each imported-variable clause has one of the following forms:

 
   identifier
   (tag identifier)
   (tag identifier  tex2html_wrap_inline8724 ) 
The first form specifies a variable imported by the compound module (through the import clause of the compound-module expression). The second form specifies a variable exported by another sub-unit in the same with clause; the tag must be different from the tag for the importing sub-module (i.e., self-import is syntactically rejected). The last form is a shorthand for multiple clauses of the second form with the same tag.

The imported-variable clauses are matched by position to the identifiers of the importing sub-unit's import clause. The number of imported-variable clauses must match the number of variables imported by the unit, although multiple tagged imported-variable clauses using the same tag can be collapsed into a single clause with one tag and multiple identifiers. If the wrong number of variables is supplied for importing, the  exn:unit:arity exception is raised and the compound unit cannot be created. If an exported variable cannot be found by name for importing into another sub-unit, the  exn:unit:import is similarly raised.

The export clause re-exports variables from the compound unit that were originally exported from the sub-units. The tag part of each export sub-clause specifies the sub-unit of the re-exported variable. The same tag can be used for multiple sub-clauses. Each exported-identifier in the export sub-clauses has one of the following forms:

 
   identifier
   (identifier exported-identifier) 
As in the export clause of the unit form, the the first form re-exports an identifier using the same exported name and the second form allows variables to be re-exported with renaming. If an exported variable cannot be found by name for re-exporting, the  exn:unit:export exception is raised.


previous up next     contents index
Next: Examples Up: Units Previous: Examples

PLT