_The Father Time Language (FrTime)_

The `frtime' collection contains the implementation of FrTime, a
language that supports declarative construction of reactive systems
through signals, or time-varying values.  Signals are classified as
either behaviors, which have a value at any point in (conceptually
continuous) time, or events, which are streams of discrete
occurrences.  Unlike (for example) boxes, the time-varying nature of
signals propagates automatically to expressions in which they are
used.

To interact with FrTime, set the language level to FrTime.  You can
also make FrTime the language for a module:

(module <module-name> (lib "frtime.ss" "frtime")
   <module-body>)

For the animation library and demo programs, set the language level
to (module ...), open the file, and execute.  The demos are perhaps
the best way to learn about FrTime.

Note that FrTime is experimental, and various aspects of it may change
significantly, though we will try our best to maintain backwards
compatibility.

_Primitive Signals_

> seconds : behavior[num]

  This behavior updates approximately every second with the value of
  (current-seconds).

> milliseconds : behavior[num]

  This behavior updates approximately every 20 milliseconds with the
  value of (current-milliseconds).  Future versions of FrTime will
  provide an interface through which the programmer can create timers
  with arbitrary update frequencies.

_Creating New Signals_

> (new-cell behavior) -> cell (a special behavior)

  The returned cell can be used as a behavior; initially its value is
  determined by the behavior given to the constructor.  For example,
  (new-cell seconds) behaves like _seconds_.  However:

> (set-cell! cell behavior) -> void

  This procedure changes the value of the cell to that of the new
  behavior.

> (event-receiver) -> event-rcvr (a special event source)

  The returned value can be used as an event source.  Specifically, it
  emits an event occurrence whenever it is used as the first argument
  to the following procedure:

> (send-event event-rcvr any) -> void

  Emits the second argument as an occurrence on the given event source.

_Signal Processors_

> (cur-val behavior[a]) -> a

  This procedure projects the current value of the given behavior.

> (delay-by behavior[a] behavior[num]) -> behavior[a]

  This procedure delays the given behavior by the given number of
  milliseconds (which need not be constant).

> (integral behavior[num] {behavior[num] = 20}) -> behavior[num]

  Computes a numeric approximation of the integral of the first
  argument with respect to time, at a minimum rate given by the second
  argument (interpreted in milliseconds).  This procedure will probably
  be rewritten soon.

> (derivative behavior[num]) -> behavior[num]

  Computes a numeric approximation of the derivative of the first
  argument with respect to time.  This procedure needs to be
  rewritten.

> (map-e event proc) -> event
> (event . ==> . proc) -> event

  Returns an event source isomorphic to the given one, except that
  each occurrence is the result of applying the given procedure to the
  input occurrence.

> (filter-e event pred) -> event
> (event . =#> . pred) -> event

  Returns a filtered version of the given event source.  Only
  occurrences that satisfy the given predicate survive.

> (merge-e event ...) -> event

  Merges all of the input event sources into a single event source.

> (once-e event) -> event

  Returns an event source that carries only the first occurrence of the
  argument event source.  (The rest are filtered out.)

> (changes behavior) -> event

  Returns an event source which occurs each time the argument behavior
  changes.  The value of the occurrence is the behavior's new value.

> (hold init event) -> behavior

  Constructs a behavior from a given initial value and an event
  source.  The value of the behavior is the value of the most recent
  event occurrence.

> (switch behavior event[behavior]) -> behavior

  Returns a behavior that "switches" each time the argument event
  occurs.

> (accum-e event[a -> a] a) -> event[a]

  Constructs an event source by accumulating changes (carried by the
  given event source) over an initial value.

> (accum-b event[a -> a] a) -> behavior[a]

  Combines functionality of accum-e and hold to construct a behavior.
  (accum-b ev init) = (hold init (accum-e ev init)).

> (collect-e event[a] b (a b -> b)) -> event[b]

  Like accum-e, except the transformer function is fixed and is applied
  to the current accumulator and the event occurrence.

> (collect-b event[a] b (a b -> b)) -> behavior[b]

  collect-b : collect-e :: accum-b : accum-e

> (when-e behavior) -> event

  The returned event source carries an occurrence each time the argument
  behavior changes from false to true (non-false).
  
> (<proc> behavior ...) -> behavior

  FrTime provides "lifted" version of many built-in procedures, including:
  add1 sub1 + - * / = equal? < > <= >= cos sin tan symbol->string symbol?
  list? number->string exp expt even? odd? list-ref string-append
  sqrt not apply number? string? zero? min max modulo car cdr null?
  string->number format

  This means that these procedures may be applied to behaviors, and the
  result automatically updates whenever any of the arguments changes.

> (require
    (lift module-spec proc-name ...)
    (lift/strict module-spec proc-name ...)
    (as-is module-spec proc-name ...)
    std-require-spec)

_Graphical Demo Programs_

demo1: Animates a collection of blue balls circling about the mouse pointer.
       The arrow keys adjust the number and speed of the balls.

demo2: Animates a simplified heat engine.  Uses GUI and animation libraries.
       Sliders adjust various lengths, and also speed.

demo3: Animates three colored balls moving around in the plane.  Up and
       down arrow keys add/remove some extra circles.

demo4: Draws a blue ball at the mouse position.  Smaller, lighter-colored
       balls trail behind.  

demo5: A ball chases the mouse around.  A gray line connects them.  The ball
       grows as it approaches the mouse.

demo6: Air-hockey/pong game.  Mouse controls right paddle.  Key-pad controls
       left paddle (num-lock must be on).

demo7(b): Networked version of demo6.