Created
December 11, 2024 12:46
-
-
Save jsks/4ef2c69ee5f878b6c3f4edc21b85f6d6 to your computer and use it in GitHub Desktop.
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
(defmacro defn-memoise [name args & body] | |
(with-syms [$cache $fun] | |
~(def ,name (let [,$cache @{} | |
,$fun (fn ,name ,args ,;body)] | |
(fn [& lst] | |
(if (nil? (,$cache lst)) | |
(set (,$cache lst) (,$fun ;lst)) | |
(,$cache lst))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment