Prev Up Next

Our engines assume the presence of a global clock or interruptable timer that marks the passage of ticks as a program executes. We will assume the following clock interface -- if your Scheme provides any kind of alarm mechanism, it should be an easy matter to rig up a clock of the following type. (Appendix T defines a clock for the Guile FSF dialect of Scheme.)

The internal state of our clock procedure consists of two items:

(1) the number of remaining ticks; and

(2) an interrupt handler to be invoked when the clock runs out of ticks.

clock allows the following operations:

(1) (clock 'set-handler h) sets the interrupt handler to h.

(2) (clock 'set n) resets the clock's remaining ticks to n, returning the previous value.

The number of ticks ranges over the non-negative integers and an atom called *infinity*. A clock with *infinity* ticks cannot run out of time and so will not set off the interrupt handler. Such a clock is quiescent or ``already stopped''. To stop a clock, set its ticks to *infinity*.

The clock handler is set to a thunk. For example,

(clock 'set-handler
  (lambda ()
    (error "Say goodnight, cat!")))

(clock 'set 9)

This will cause an error to be signaled after 9 ticks have passed, and the message displayed by the signal will be ``Say goodnight, cat!''

Prev Up Next

Log in or registerto write something here or to contact authors.