Skip to content

Instantly share code, notes, and snippets.

@bmabey
Created August 10, 2011 05:00
Show Gist options
  • Save bmabey/1136161 to your computer and use it in GitHub Desktop.
Save bmabey/1136161 to your computer and use it in GitHub Desktop.
memoized anonymous functions in clojure
; 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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment