Skip to content

Instantly share code, notes, and snippets.

@pepijndevos pepijndevos/fib.clj
Created Jan 4, 2010

Embed
What would you like to do?
(require 'clojure.contrib.lazy-seqs)
(defmacro fib [nr]
(let [fibfn (gensym fib)]
`(let [~fibfn (fn [nrs#] [(peek nrs#) (+ (first nrs#) (peek nrs#))])]
(-> [0 1] ~@(take nr (repeat fibfn))))))
(println (time (last (fib 10))))
(println (time (nth (clojure.contrib.lazy-seqs/fibs) 11)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.