On Sun, Oct 4, 2009 at 4:41 PM, samppi <rbysam...@gmail.com> wrote: > > I want to do this: > > (defn a ...) > (cache a) ; or (cache #'a) or (cache 'a); it doesn't matter to me > > ...instead of this: > > (def a (memoize (fn ...))) > > That way, it separates the concern of what a does from the > optimization I'm doing on it. Now, I'm kind of stuck; how should I do > it? > > (defn cache > "Replaces the function that the given variable refers to > with a memoizing version of it." > [fn-var] > (??? fn-var (memoize @fn-var)))
Why not use a macro? (defmacro cache "Replaces the function that the given variable refers to with a memoizing version of it." [fn-var-name] `(def ~fn-var-name (memoize ~fn-var-name))) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---