Created
December 19, 2010 18:31
-
-
Save rlm/747571 to your computer and use it in GitHub Desktop.
an example of recursion with re-dispatch on multimethods
This file contains hidden or 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
(defmulti redis class) | |
(defmethod redis java.lang.Integer [x] x) | |
(defmethod redis java.lang.Double [x] | |
(let [res (if (< (- x (int (floor x))) 0.01) | |
(int x) | |
(/ x 2))] | |
(println x) | |
(fn [] ((get-method redis ((.dispatchFn redis) res)) res)) | |
)) | |
;; call like this: | |
(trampoline redis 64.05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment