Created
January 4, 2010 21:06
-
-
Save pepijndevos/268866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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