Last active
May 27, 2017 14:08
-
-
Save deque-blog/2a04b9e61ef73e3c2ba47aa6c015c9c5 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
(defprotocol Advance | |
(advance [this n])) | |
(deftype FiboType [^:unsynchronized-mutable curr | |
^:unsynchronized-mutable next] | |
Advance | |
(advance [_ n] | |
(loop [^long n n] | |
(if-not (zero? n) | |
(let [nnext (+ curr next)] | |
(set! curr next) | |
(set! next nnext) | |
(recur (dec n))))) | |
curr)) | |
(defn fibo-with-type | |
[^long n] | |
(advance (FiboType. 0N 1N) n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment