Wow!! Lots of responses!

The problem was that I was running the code inside of a jark repl. The jark
repl apparently causes head holding of some sort.

All the examples you guys provided (@Allen, @Jonas, @Baishampayan) work in
a regular project from lein run.

They also work from the leiningen repl.

Thank you guys very much! I got this working and my problem was the jark
repl.

On Tue, May 1, 2012 at 11:44 PM, Baishampayan Ghose <b.gh...@gmail.com>wrote:

> > The problems
> >
> > I can't use map as in (map println (file-seq (java.io.File.
> > "/DirectoryWithMillionsOfFiles"))). Map realizes the sequence.
>
> You can't use `map` because `map` will return a sequence of the same
> size and that can blow your heap.
>

Right.


>
> > I can't use for as in (for [x (files)] (println x)). For realizes the
> > sequence.
> > I can't use dorun because even though dorun doesn't realize the
> sequence, it
> > can't execute a function on every element.
> > 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)))
>
> Going by the examples here, it seems you are holding on the head by
> binding the while file-seq to a var called `files`. That is the
> problem.
>
> Take a look at my loop-recur example. You'll see that I create a
> temporary binding that gets reduced in size every time I recur. So in
> that example, I am not holding on to the head anywhere and the files
> that I have printed will get GCd quickly without blowing up.
>
> To repeat, the problem is in holding on to the head (ie. the whole
> sequence) and if you process every item and throw away items from the
> seq there shouldn't be any problem.
>

Ok. And rest can do that because rest returns a lazy sequence.


>
> Regards,
> BG
>
> --
> Baishampayan Ghose
> b.ghose at gmail.com
>
> --
> 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

Reply via email to