I have a question on how to do a memoization for functions that require two inputs. I have the code for how to do a memoization for something like finding the nth fibonacci number, which I will post here:
(define (fib3 n)
(local
{(define hash identity)
(define v (make-vector (add1 n) empty))
(define (get n l) ; num (listof pair) -> false or the pair with n
(cond
[(empty? l) false]
[(= (pair-a (first l)) n) (first l)]
[else (get n (rest l))]))
(define (put n r) ; num result -> result
(begin (vector-set! v (hash n) (cons (make-pair n r) (vector-ref v (hash n))))
r))
(define (fib-helper n)
(match (get n (vector-ref v (hash n)))
[(struct pair (_ b)) b]
[false (put n (cond
[(= n 0) 1]
[(= n 1) 1]
[else (+ (fib-helper (- n 1)) (fib-helper (- n 2)))]))]))}
(fib-helper n)))
However, I am a bit confused on how to implement it for a binomial coefficient function. My normal recursive case looks like this:
(define (comb-recursive m l)
(cond
[(< m l) 0]
[(or (= l 0) (= m l)) 1]
[else (+ (comb-recursive (sub1 m) (sub1 l))
(comb-recursive (sub1 m) l))]))
I do not really know how to change this such that it does memoization. Are there any tips that would help me tackle this question and use a format similar to the fib function described above? Thanks in advance!