Re: with-open and for

2013-06-11 Thread John D. Hume
On Jun 11, 2013 8:25 AM, "Meikel Brandmeyer (kotarak)" wrote: > Or another one: > > (defn filter-lines > [rdr] > (->> (line-seq rdr) > (mapcat #(str/split % #"\s+")) > (filter #(<= 4 (count %) 9)) > (into #{}))) > > (defn filter-file > [filename] > (with-open [rdr (io/reader fi

Re: with-open and for

2013-06-11 Thread Meikel Brandmeyer (kotarak)
Or another one: (defn filter-lines [rdr] (->> (line-seq rdr) (mapcat #(str/split % #"\s+")) (filter #(<= 4 (count %) 9)) (into #{}))) (defn filter-file [filename] (with-open [rdr (io/reader filename)] (filter-lines rdr))) Meikel Am Dienstag, 11. Juni 2013 11:04:14 UTC+2

Re: with-open and for

2013-06-11 Thread Jean Niklas L'orange
I haven't seen the use of multiple statements in the for comprehension here, so perhaps it's nice to elaborate that this exists? (defn filter-file [filename] (with-open [rdr (io/reader filename)] (set (for [line (line-seq rdr) word (str/split line #"\s+") :when (<

Re: with-open and for

2013-06-11 Thread Ray Miller
The 'reduce' solution is very elegant, but you can simplify it further: (defn filter-file [filename] (with-open [rdr (io/reader filename)] (reduce (fn [words line] (into words (filter #(<= 4 (count %) 9) (str/split line #"\s+" #{} (line-seq rdr

Re: with-open and for

2013-06-10 Thread Thomas Heller
Hey, I pasted the code into gist ( https://gist.github.com/thheller/5734642 ) and copy&pasted that into the post. Cheers, /thomas On Mon, Jun 10, 2013 at 6:01 PM, Alan Thompson wrote: > Hey Thomas - How'd you get the nice syntax highlighting in your post? > Alan > > > On Sat, Jun 8, 2013 at 7:

Re: with-open and for

2013-06-10 Thread Alan Thompson
Hey Thomas - How'd you get the nice syntax highlighting in your post? Alan On Sat, Jun 8, 2013 at 7:16 PM, Steven D. Arnold wrote: > Thanks for the responses! As suggested, wrapping in 'doall' does work. > > > On Jun 8, 2013, at 3:28 AM, Thomas Heller wrote: > > (defn filter-file [filename] >

Re: with-open and for

2013-06-08 Thread Steven D. Arnold
Thanks for the responses! As suggested, wrapping in 'doall' does work. On Jun 8, 2013, at 3:28 AM, Thomas Heller wrote: > (defn filter-file [filename] > (with-open [rdr (io/reader filename)] >(reduce (fn [words line] > (->> (str/split line #"\s+") > (filter

Re: with-open and for

2013-06-08 Thread Thomas Heller
Hey, for produces a lazy sequence (as does flatten) which is hurting you here. You could wrap everything in a doall but I'd recommend using reduce since thats technically what you want here. I'd probably go for something like: (defn filter-file [filename] (with-open [rdr (io/reader filename)

Re: with-open and for

2013-06-07 Thread Lars Nilsson
On Sat, Jun 8, 2013 at 12:53 AM, Steven D. Arnold wrote: > (defn filter-file > [] > (with-open [rdr (reader "/Users/thoth/wordlist.txt")] >(flatten > (for >[line (line-seq rdr)] >(filter > (and #(<= (count %) 9) > #(>= (count %) 4)) > (spl