Skip to content

Instantly share code, notes, and snippets.

@jsks
Created December 11, 2024 12:46
Show Gist options
  • Save jsks/4ef2c69ee5f878b6c3f4edc21b85f6d6 to your computer and use it in GitHub Desktop.
Save jsks/4ef2c69ee5f878b6c3f4edc21b85f6d6 to your computer and use it in GitHub Desktop.
(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