Created
August 10, 2011 05:00
-
-
Save bmabey/1136161 to your computer and use it in GitHub Desktop.
memoized anonymous functions in clojure
This file contains 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
; 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