Version: 4.2.1

14.2 Invoking Units

The simple-factory@ unit has no imports, so it can be invoked directly using invoke-unit:

  > (require "simple-factory-unit.ss")
  > (invoke-unit simple-factory@)

  Factory started.

The invoke-unit form does not make the body definitions available, however, so we cannot build any toys with this factory. The define-values/invoke-unit form binds the identifiers of a signature to the values supplied by a unit (to be invoked) that implements the signature:

  > (define-values/invoke-unit/infer simple-factory@)

  Factory started.

  > (build-toys 3)

  (#(struct:toy blue) #(struct:toy blue) #(struct:toy blue))

Since simple-factory@ exports the toy-factory^ signature, each identifier in toy-factory^ is defined by the define-values/invoke-unit/infer form. The /infer part of the form name indicates that the identifiers bound by the declaration are inferred from simple-factory@.

Now that the identifiers in toy-factory^ are defined, we can also invoke toy-store@, which imports toy-factory^ to produce toy-store^:

  > (require "toy-store-unit.ss")
  > (define-values/invoke-unit/infer toy-store@)
  > (get-inventory)

  ()

  > (stock! 2)
  > (get-inventory)

  (#(struct:toy green) #(struct:toy green))

Again, the /infer part define-values/invoke-unit/infer determines that toy-store@ imports toy-factory^, and so it supplies the top-level bindings that match the names in toy-factory^ as imports to toy-store@.