What a lifesaver! Thanks a lot!
On Oct 4, 2:58 pm, Meikel Brandmeyer <m...@kotka.de> wrote:
> Hi,
>
> Am 04.10.2009 um 22:47 schrieb talk:
>
> >> (defn cache
> >> "Replaces the function that the given variable refers to
> >> with a memoizing version of it."
> >> [fn-var]
> >> (??? fn-var (memoize @fn-var)))
>
> Macros to the rescue:
>
> (defmacro cache
> "Replaces the function that the given name refers to
> with a memoizing version of it."
> ([fn-sym] `(cache ~fn-sym ~fn-sym))
> ([fn-cached fn-uncached]
> `(let [var-meta# (meta (var ~fn-uncached))]
> (def ~fn-cached (memoize ~fn-uncached))
> (reset-meta! (var ~fn-cached) var-meta#)
> (var ~fn-cached))))
>
> Sincerely
> Meikel
>
> smime.p7s
> 3KViewDownload
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---