Re: Memoizing tree recursive calls

2010-07-21 Thread Mike Meyer
On Tue, 20 Jul 2010 13:11:12 -0700 (PDT) Aravindh Johendran wrote: > If we have tree recursive procedure such as the follows, how can we > use memoize it so that it automatically caches the values it has > already computed . [example elided] > Maybe memoize should go the same way as the co

Re: Memoizing tree recursive calls

2010-07-20 Thread MichaƂ Marczyk
On 20 July 2010 23:41, Moritz Ulrich wrote: > I think the tour problem is the (def m-fib (memoize fib)). You create > a new memoized function m-fib, while fib will internally call the > non-memoized fib. You have to do something like: (binding [fib > (memoize fib)] (fib 42)). > However, this will

Re: Memoizing tree recursive calls

2010-07-20 Thread Moritz Ulrich
Offtopic: Java doesn't support tail-recursive calls, so your fib will blow up the stack for larger ns. Use recur for recursion. I think the tour problem is the (def m-fib (memoize fib)). You create a new memoized function m-fib, while fib will internally call the non-memoized fib. You have to do s

Memoizing tree recursive calls

2010-07-20 Thread Aravindh Johendran
If we have tree recursive procedure such as the follows, how can we use memoize it so that it automatically caches the values it has already computed . (defn fib [n] (println "Calling fib with arg --> " n) (cond (= n 0) 0 (= n 1) 1 :else (+ (fib (- n 1)) (fib (- n 2)))