You can also use doseq afaik, altough every element must realized at least once, you just have to make sure you don't hold onto the head of the sequence as you proceed.
It is not immediately apparent to me why that doesn't happen with your loop-recur solution On May 2, 2012 6:27 AM, "Sean Neilan" <s...@seanneilan.com> wrote: > I forgot to mention: > (nth (file-seq (java.io.File. "/DirectoryWithMillionsOfFiles/")) 200000) > works great because nth doesn't realize the sequence! > > For now, I'll look at nth's source code to see how it iterates. > > On Tue, May 1, 2012 at 11:24 PM, Sean Neilan <sneil...@gmail.com> wrote: > >> Hi, >> >> I'm sure this has been discussed to death but I can't figure it out. >> >> I've got a file-seq sequence from >> (file-seq (java.io.File. "/DirectoryWithMillionsOfFiles/")) that will >> cause an out of memory error if realized. >> >> I want to call a function such as println on every element in the >> sequence. >> >> I understand that naming the sequence will cause it to be realized. >> >> The problems >> >> 1. I can't use map as in (map println (file-seq (java.io.File. >> "/DirectoryWithMillionsOfFiles"))). Map realizes the sequence. >> 2. I can't use for as in (for [x (files)] (println x)). For realizes >> the sequence. >> 3. I can't use dorun because even though dorun doesn't realize the >> sequence, it can't execute a function on every element. >> 4. I can't use loop recur because it also realizes the >> sequence: (loop [a (files) b (first a)] (println b) (recur (rest a) (first >> a))) >> 5. I can't use refs because even though they provide state, they >> can't save the state of the sequence without realizing the sequence. >> >> My question >> *Should I try the new stream library?* >> * >> * >> Thank you for your time. >> >> -Sean >> >> > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en