public
Last active

memoized anonymous functions in clojure

  • Download Gist
memoize_fn.clj
Clojure
1 2 3 4 5 6 7 8 9
; inspired from http://stackoverflow.com/questions/3906831/how-do-i-generate-memoized-recursive-functions-in-clojure
(defmacro memoize-fn
"Produces a memoized anonymous function that can recursively call itself."
[fn-name & fn-args]
`(with-local-vars
[~fn-name (memoize
(fn ~@fn-args))]
(.bindRoot ~fn-name @~fn-name)
@~fn-name))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.