Created
October 23, 2015 22:46
-
-
Save xfsnowind/747bea967cc71009a6f7 to your computer and use it in GitHub Desktop.
official standard memoize function
This file contains hidden or 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
(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