Created
February 26, 2010 01:01
-
-
Save anonymous/315268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; For versions of Clojure that don't have metadata on functions, this | |
;; allows you to reset the atom by passing the magic argument :reset! | |
(defn memoize-visible-atom-hack [f] | |
(let [mem (atom {})] | |
(fn [& args] | |
(if (= (first args) :reset!) | |
(reset! mem {}) | |
(if-let [e (find @mem args)] | |
(val e) | |
(let [ret (apply f args)] | |
(swap! mem assoc args ret) | |
ret)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment