Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Created January 4, 2010 21:06
Show Gist options
  • Save pepijndevos/268866 to your computer and use it in GitHub Desktop.
Save pepijndevos/268866 to your computer and use it in GitHub Desktop.
(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