[previous] [up] [next]     [contents] [index]
Next: Invoking and Opening Units Up: Linking Units and Creating Previous: Linking Units and Creating

Examples

These examples use the definitions from the earlier unit examples in section 7.1.1.

The following compound-unit expression creates a useless wrapping around the unit bound to f1@:

  (define f3@
    (compound-unit
      (import)
      (link [A (f1@)])
      (export (A (x A:x)))))

The only difference between f1@ and f3@ is that f1@ exports a variable named x, while f3@ exports a variable named A:x.

The following example shows how the database@ and interface@ units are linked together with a graphical toolbox unit Graphics to produce a single, fully-linked compound unit for the interactive phone book program.

  (define program@
    (compound-unit 
      (import)
      (link (GRAPHICS (graphics@))
            (DATABASE (database@ (INTERFACE show-message)))
            (INTERFACE (interface@ (DATABASE insert lookup)
                                   (GRAPHICS make-window make-button))))
            (export)))

This phone book program is executed with (invoke-unit program@). If (invoke-unit program@) is evaluated a second time, then a new, independent database and window are created.



PLT