Skip to content

Instantly share code, notes, and snippets.

Created February 26, 2010 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/315268 to your computer and use it in GitHub Desktop.
Save anonymous/315268 to your computer and use it in GitHub Desktop.
;; 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