15 (else (+ (memo-fib (- n 1))
16 (memo-fib (- n 2))))))))
19 (let ((previous-output (make-table)))
21 (let ((lookup-result (lookup x previous-output)))
25 (insert! x result previous-output)
30 If we define memo-fib as
35 and say, call (memo-fib 10), then, we cache the result of calling fib with n=10.
36 But (fib n) calls (fib (- n 1)) and (fib (- n 2)) and this way of calling memo-fib won't cache those intermediate values.
38 On the other hand, if we define memo-fib the way it is defined above, all intermediate calls to memo-fib also goes through memoize call and hence will get cached in the results table. Hence this is much more efficient.