On Thu, Jan 19, 2012 at 9:46 PM, Cedric Greevey <cgree...@gmail.com> wrote: > Something like > > (defn make-memoized [some-param] > (let [cache (atom {})] > (fn [& args] > (when-not (contains? cache args) > (swap! cache assoc args (expensive-computation some-param args))) > (cache args)))) >
Two points: 1. I want the expensive-computation to be recursive. I think this can be done by adding name to the anonymous function between the fn and the [& args]. 2. Ideally, I don't want to clutter my code by restating the caching behavior every time I do this. I'd like to leverage something like the built in memoize. That's what I don't think is possible. However, you've given me an idea that maybe I can just write a macro, something like (memofn fib [x] (if (<= n 1) n (+ (fib (dec n)) (fib (- n 2))))) which would expand into something that would work locally. -- 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