Re: Stackoverflow on a function listing files in a directory recursively

2013-05-20 Thread Gary Trakhman
Ramesh, I think the main problem is you're trying to do a recursion over a tree, so you're blowing a stack if you're not careful, concat is lazy so I think you're just shifting the problem around, file-seq gets around this by using tree-seq, which uses 'walk', which is a linearization of the tree.

Re: Stackoverflow on a function listing files in a directory recursively

2013-05-20 Thread Gary Trakhman
yes it does.. user> (clojure.pprint/pprint (take 20 (file-seq (clojure.java.io/file"/" (# # # # # # # # # # # # # # # # # # # #) On Mon, May 20, 2013 at 4:43 PM, Jim - FooBar(); wrote: > well no it doesn't descent into directories...I just tried it... > > Jim > > > On 20/

Re: Stackoverflow on a function listing files in a directory recursively

2013-05-20 Thread Ramesh
So, I think concat is the problem here. I wish there were recommendation for other options and reason in the Stacktrace to help me code better! And file-seq is exactly what I'm looking for :). Thanks all! Thanks, ramesh On Mon, May 20, 2013 at 1:21 PM, Ben Wolfson wrote: > Basically, you can

Re: Stackoverflow on a function listing files in a directory recursively

2013-05-20 Thread Jim - FooBar();
well no it doesn't descent into directories...I just tried it... Jim On 20/05/13 21:39, Jim - FooBar(); wrote: actually yes it is! :) I thought file-seq was going down one level only but looking at the implementation it seems it goes down all levels...I'm trying it out now Jim On 20/05/13 2

Re: Stackoverflow on a function listing files in a directory recursively

2013-05-20 Thread Jim - FooBar();
actually yes it is! :) I thought file-seq was going down one level only but looking at the implementation it seems it goes down all levels...I'm trying it out now Jim On 20/05/13 21:31, Gary Trakhman wrote: Is this not sufficient? file-seq https://github.com/clojure/clojure/blob/master/src/cl

Re: Stackoverflow on a function listing files in a directory recursively

2013-05-20 Thread Gary Trakhman
Is this not sufficient? file-seq https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L4478 On Mon, May 20, 2013 at 4:28 PM, Jim - FooBar(); wrote: > have you considered using mapcat recursively? something like this > perhaps? > > (defn list-all-files [^java.io.File dir] >

Re: Stackoverflow on a function listing files in a directory recursively

2013-05-20 Thread Jim - FooBar();
have you considered using mapcat recursively? something like this perhaps? (defn list-all-files [^java.io.File dir] (let [children (.listFiles dir) directories (filter #(.isDirectory %) children) files (filter #(.isFile %) children)] (concat files (mapcat list-all-files dire

Re: Stackoverflow on a function listing files in a directory recursively

2013-05-20 Thread Ben Wolfson
Basically, you can't use "concat" in a loop like that. You could wrap it in a (doall ...) to avoid the stack overflow. On Mon, May 20, 2013 at 1:12 PM, Ramesh wrote: > Hi all, > > I have the following function to list all the files recursively under a > directory. > > (defn list-all-files2 [pat

Stackoverflow on a function listing files in a directory recursively

2013-05-20 Thread Ramesh
Hi all, I have the following function to list all the files recursively under a directory. (defn list-all-files2 [path] (let [basepath (java.io.File. path)] (loop [origlist [basepath] finallist []] (if-let [cur (first origlist)] ;This line is not required (if (.isDirectory cur) (recur (concat (