Each delayed object stores its own value after the first time it's forced; the value is stored in the result
variable. It works because memo-proc
creates a closure over both proc
- the promise (a no-arg procedure waiting to be evaluated) and the result
variable.
After the first time the object is forced the stored result
is returned, and never again is recalculated. So the promise becomes the value itself.
I don't see how memoization is achieved without using a lookup table, or some other kind of data structure which accumulates the previous calls.
The data structure is the closure created around each promise, it accumulates the value of the first call in the result
variable, returning it for all subsequent calls.
Hence, I'm feeling like a memoized value won't ever be read by any other procedures again
Yes, it'll be read each and every time that force
is called on the promise object.