Sat Mar 27 16:08:26 CET 2010

Naive Reactive Program

I want to implement a reactive programming system to serve as a
website cache.  I.e. `make' combined with input events.

   - PUSH: do not propagate invalid inputs past invalid nodes; a
           network invariant is that

   - PULL: only compute what is necessary

   Network invariant: a valid node can never depend on an invalid one.

The PULL part is easy: it's essentially a lazy value (delay/force).

The PUSH part is more difficult in practice.  There are 2 problems:

    - reverse the linking to enable the PUSH propagation

    - unlink when a value gets collected (finalizers).

Setting up the dependencies in the first place seems to be the hardest
problem.  Let's focus on that first.

It seems it's best to solve registration at node creation time.  A
node is a computation that is parameterized by a set of nodes.  Let's
curry the procedure so it deals with all non-node (constant)
arguments.  The form then becomes.

    (rp-app fn n1 n2 ...)

This takes a strict function fn and a number of nodes.  The nodes are
evaluated and the struct function is applied to it.

Due to lexical scope, a node does not need an explicit store of its
parents: this is available in the rp-app_ function.

For the rp-register-child! function we need weak references.  It seems
a weak hash table is the easiest way to implement this.

Apparently finalizers aren't necessary: the weak hash table
automatically removes references that are no longer valid.