Skip to content

Instantly share code, notes, and snippets.

@xfsnowind
Created October 23, 2015 22:46
Show Gist options
  • Save xfsnowind/747bea967cc71009a6f7 to your computer and use it in GitHub Desktop.
Save xfsnowind/747bea967cc71009a6f7 to your computer and use it in GitHub Desktop.
official standard memoize function
(defn memoize
[f]
(let [mem (atom {})]
(fn [& args]
(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