(define (memo-proc proc)
(let ((already-run? #f)
(result '()))
(lambda ()
(if already-run?
result
(begin (set! result (proc))
(set! already-run? #t)
result)))))
memo-proc ensures that a given function proc
will only be run once and it's value is cached for later reuse.
It is implemented as a special form where a closure is setup to keep track of when to execute the proc and when to return it's already computed value.
This module is used by: