Created
February 1, 2012 09:06
-
-
Save simonjefford/1716056 to your computer and use it in GitHub Desktop.
Y U NO Lazy?
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
(defn seq-from-nodelist [nodelist] | |
(let [nodecount (.getLength nodelist)] | |
(for [i (range nodecount)] | |
(do | |
(println "node") | |
(.item nodelist i))))) | |
;; nodelist contains 5 nodes | |
(def nodes (seq-from-nodelist nodelist)) | |
;; prints node 5 times | |
(first nodes) | |
;; where as... | |
(defn lazytest [] | |
(for [x (iterate inc 0)] | |
(do | |
(println "double") | |
(* 2 x)))) | |
(def doubles (lazytest)) | |
;; prints "double" once | |
(first doubles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment