Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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