previous up next     contents index
Next: Utilities Up: Invoking Units Previous: Invoking Units

Examples

These examples use the definitions from the earlier unit examples in section 2.16.1 and section 2.16.2.

Invoking f1@, f2@, or f3@ produces the same result:

  (invoke-unit f1@) ; displays and returns the current time
However, invoking and opening f1@ binds different global variables than invoking and opening f3@:
  (invoke-open-unit f1@) ; displays and returns the current time
  x ; => time that was displayed
  (invoke-open-unit f3@) ; displays and returns the current time
  x ; => still time that was displayed by invoking f1@
  A:x ;  => time that was displayed by invoking f3@
  (invoke-open-unit f1@) ; displays and returns the current time
  x ; => time that was displayed by most recent invocation of f1@

Invoking appointment-reminder@ spawns a new thread for checking appointments:

  (invoke-unit appointment-reminder@) ; => #<void>
Although last-checker-date was exported by appointment-reminder@, it was not imported into any other unit so it is completely inaccessible. However, we can inspect this variable when the unit is invoked and opened:
  (invoke-open-unit appointment-reminder@) ; => #<void>
  CHECKER:last-check-date ; => last time datebook was checked
This creates a second appointment reminder; the original appointment reminder is still running with independent variables. If, however, we open the unit again:
  (invoke-open-unit appointment-reminder@) ; => #<void>
the unit bodies are re-evaluated and a third checker thread is spawned, but the same global variables are used by the second and third threads.



PLT