1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
S9 LIB (define-memoizing <name> <procedure>) ==> procedure
(define-memoizing (<name> <args>) <body>) ==> procedure
(memoize procedure) ==> procedure
(memoize procedure 'reset) ==> procedure
(load-from-library "memoize.scm")
MEMOIZE turns the given procedure into a "memoizing" procedure
that stores intermediate results in an internal cache in order
to speed up computation. This works best for massively recursive
procedures.
When the 'RESET keyword is passed to MEMOIZE as a second argument,
the resulting memoizing procedure will allow to clear its cache
by calling it with 'RESET as its only argument.
DEFINE-MEMOIZING is like DEFINE but defines a memoizing procedure.
Procedures created with DEFINE-MEMOIZING always interpret 'RESET
as a special argument for clearing their caches.
(letrec
((fib
(memoize
(lambda (x)
(if (< x 2)
1
(+ (fib (- x 1))
(fib (- x 2))))))))
(fib 100)) ==> 573147844013817084101
|