Memoization
We pick up again our dicussion of streams, and show how a careful use of
state can memoize computed elements, i.e., save their value so that it does
not need to be recomputed the next time it is needed. Memoization ensures
that a suspended expression is evaluated at most once. When a suspension is
forced for the first time, its value is stored in a reference cell and
simply returned when the suspension is forced again. The implementation that
we present makes a subtle and elegant use of a "self-modifying" code
technique with circular references.