Re: apply a function to every item in a sequence without realizing the sequence

2012-05-02 Thread Michał Marczyk
Note also that in the REPL the last three values returned are kept available under *1, *2 and *3. M. On 2 May 2012 15:40, Allen Johnson wrote: > My example included a use of `map`. It is lazy and will work but you > have to be sure that you aren't using it in a way that would hold onto > the he

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-02 Thread Allen Johnson
My example included a use of `map`. It is lazy and will work but you have to be sure that you aren't using it in a way that would hold onto the head of the sequence. When experimenting in a repl it might not seem that it is lazy since the repl will attempt to print the result of calling map when t

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-02 Thread Baishampayan Ghose
On Wed, May 2, 2012 at 12:01 PM, Sean Neilan wrote: > I don't think so. Of course it is. The problem is not in laziness, but in holding on to the head. Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- You received this message because you are subscribed to the Google Groups "Clojure

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread László Török
Map IS lazy but it still returns the entire realized sequence, as expected. On May 2, 2012 8:31 AM, "Sean Neilan" wrote: > I don't think so. > > On Wed, May 2, 2012 at 1:22 AM, Stuart Campbell wrote: > >> On 2 May 2012 14:44, Baishampayan Ghose wrote: >> >>> You can't use `map` because `map` wi

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Sean Neilan
I don't think so. On Wed, May 2, 2012 at 1:22 AM, Stuart Campbell wrote: > On 2 May 2012 14:44, Baishampayan Ghose wrote: > >> You can't use `map` because `map` will return a sequence of the same >> size and that can blow your heap. >> > > Isn't `map` lazy too? > > Regards, > Stuart > > -- > Yo

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Stuart Campbell
On 2 May 2012 14:44, Baishampayan Ghose wrote: > You can't use `map` because `map` will return a sequence of the same > size and that can blow your heap. > Isn't `map` lazy too? Regards, Stuart -- You received this message because you are subscribed to the Google Groups "Clojure" group. To po

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Sean Neilan
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 rep

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Baishampayan Ghose
> 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. > I can't use for as in (for [x (files)] (println

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread László Török
Wow lot of active people in the early morning, all typing faster than me on my phone... :-) On May 2, 2012 6:36 AM, "László Török" wrote: > 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

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread László Török
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"

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Allen Johnson
Do you have example code that is failing? You should be able to use some of the items you listed as "problems". Try something like this: (->> (file-seq (io/file "/some/dir")) (map println) (dorun)) AJ On Wed, May 2, 2012 at 12:26 AM, Sean Neilan wrote: > I forgot to mention: > (nth

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Baishampayan Ghose
Sean, > 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 t

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Jonas
On Wednesday, May 2, 2012 7:24:04 AM UTC+3, Sean Neilan 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 realize

Re: apply a function to every item in a sequence without realizing the sequence

2012-05-01 Thread Sean Neilan
I forgot to mention: (nth (file-seq (java.io.File. "/DirectoryWithMillionsOfFiles/")) 20) 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 wrote: > Hi, > > I'm sure this has bee