Created
April 18, 2012 06:56
-
-
Save jmgimeno/2411576 to your computer and use it in GitHub Desktop.
Does not hold the head of a sequance only its first element and the generating function.
This file contains hidden or 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
(defn crazy-seq [head f] | |
(reify | |
clojure.lang.ISeq | |
(first [_] head) | |
(more [_] (crazy-seq (f head) f)) | |
(next [this] (rest this)) | |
(seq [this] this) | |
(equiv [_ _] false))) | |
(def s (crazy-seq 0 inc)) ; hold head | |
(dorun (take 100000000 s)) ; low fat | |
(nth s 10) ; recomputes | |
;=> 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment