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/a6a80528fb2a1bdca452b9429f4aa844 to your computer and use it in GitHub Desktop.
Save deque-blog/a6a80528fb2a1bdca452b9429f4aa844 to your computer and use it in GitHub Desktop.
(defn fibo-volatile
[^long n]
(let [curr (volatile! 0N)
next (volatile! 1N)
iter (volatile! n)]
(while (> @iter 0)
(let [nnext (+ @curr @next)]
(vreset! curr @next)
(vreset! next nnext)
(vswap! iter dec)))
@curr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment