Hi, As a side note, do you know that (as far as I understand your need), what you're trying to achieve already exists and is called memoize :
http://clojure.org/api#toc366 HTH, -- Laurent 2009/4/27 Tzach <[email protected]>: > > Hi all > I’m playing on a mechanism for function call results caching. > This can be used to improve performance in case of a complex or > remote function call. > The basic idea is as follow: > > ;; The cache is implement as a global map. Function arguments are the > key, the return result is the value. > (def *cache* (hash-map)) > > ;; first check the cache, > ;; if result not already exist – call function and store result > (defmacro cache-call [f & args] > `(let [cached# (get *cache* (list ~...@args))] > (if cached# > cached# > (let [ret# (~f ~...@args)] > (def *cache* (assoc *cache* (list ~...@args) ret#)) > ret#) ))) > > usage: > (cache-call + 1 2) > > This works fine, but pretty messy. > I would like to scope the hash-map inside the macro and have a hash- > map per function. > How can I do it? > Any style, idioms or personal comments are more than welcome. > > Thanks > Tzach > > P.S. > At a second phase I would like to let the user extend the caching > properties per function, e.g. cache size, refresh algorithm etc. > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---
