-
-
Save tomjack/f04db48b5f33d4810de2 to your computer and use it in GitHub Desktop.
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
scratch.case-fact> (defmacro caseify [f n] `(fn [x#] (case x# ~@(mapcat (juxt identity (resolve f)) (range n))))) | |
#'scratch.case-fact/caseify | |
scratch.case-fact> (macroexpand-1 '(caseify fact 10)) | |
(clojure.core/fn [x__9437__auto__] (clojure.core/case x__9437__auto__ 0 1 1 1 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320 9 362880)) | |
scratch.case-fact> (def digit-fact (caseify fact 10)) | |
#'scratch.case-fact/digit-fact | |
scratch.case-fact> (digit-fact 9) | |
362880 | |
scratch.case-fact> (def memo-fact (memoize fact)) | |
#'scratch.case-fact/memo-fact | |
scratch.case-fact> (memo-fact 9) | |
362880 | |
scratch.case-fact> (time (dotimes [_ 10000000] (memo-fact 9))) | |
"Elapsed time: 1464.514172 msecs" | |
nil | |
scratch.case-fact> (time (dotimes [_ 10000000] (digit-fact 9))) | |
"Elapsed time: 173.222382 msecs" | |
nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment