I realize that this is my fault, I misunderstood the `memoize` and I search the mail list and find this issue already solved. Sorry to raise this issue again. The right way to use memoization with recursion is to use the "memoized" method in stead of call the raw "unmemoized" method. @Paulo Sérgio Almeida 's solution just the thing i wanted. BTW, I found the lazy way is more effective then TCO, the loop-recur I mean, and memoization. Using build-in lazy funciton perform better.
On Saturday, April 13, 2013 12:52:28 PM UTC+8, Liao Pengyu wrote: > > Hi, there. I have a question about the memoization in clojure. > I compare two functions to test the performance improvement of memoization: > (defn fib [n] > (if (or (zero? n) (= n 1)) > 1 > (+ (fib (dec n) ) (fib (- n 2))))) > > (time (fib 30)) > get the result: > "Elapsed time: 316.65 msecs" > 1346269 > > And then test for memoization: > user> (time ((memoize fib-nocur) 30)) > "Elapsed time: 308.729 msecs" > 1346269 > user> (time ((memoize fib-nocur) 30)) > "Elapsed time: 314.942 msecs" > 1346269 > user> (time ((memoize fib-nocur) 30)) > "Elapsed time: 308.657 msecs" > 1346269 > > Seems no effect. Since I just test it in nrepl and have no experience > about using clojure in project, I wander was the memoization really works? > Look forward to your responses > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.