Memoization wraps a function with a cache keyed by its complete argument list. Repeated calls return the stored result without recomputation, while preserving the function's public interface. section 2.4.2
Use memoization when:
- The computation is expensive, accepts values with a small memory footprint, and receives a finite or estimable set of repeated inputs. section 2.4.2
- The wrapped function must accept variable arity; supply a callable function, or expect ClassCastException and missing-argument ArityException. section 2.4.2
Cache misses happen once per argument list
(defn- f* [a b] (println (format "Cache miss for [%s %s]" a b)) (+ a b)) (def f (memoize f*)) (f 1 2) ; prints a miss, returns 3 (f 1 2) ; returns 3 without printing (f 1 3) ; prints a miss, returns 4







