Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active May 27, 2017 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/2a04b9e61ef73e3c2ba47aa6c015c9c5 to your computer and use it in GitHub Desktop.
Save deque-blog/2a04b9e61ef73e3c2ba47aa6c015c9c5 to your computer and use it in GitHub Desktop.
(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