On 23 Lip, 01:51, Paul Mooser <taron...@gmail.com> wrote: > Why not simply do: > > (defn fib [n] > (println "called with " n) > (if (> n 2) > (+ (fib (- n 2)) (fib (- n 1))) > 1)) > > (def fib (memoize fib)) > > I inserted the println to verify when we were actually calling the > function, and I believe this works - fib only seems to get invoked a > single time for any given n. Is this solution incorrect in some way?
It uses up stack (becuase you recursive call fib directly, not thrught recur). For big values of n it could cause stack overflow. -- 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