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))))
Ray. On 10 June 2013 18:20, Thomas Heller <i...@zilence.net> wrote: > 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 <thompson2...@gmail.com> > wrote: >> >> 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 >> <thoth.amon.i...@gmail.com> wrote: >>> >>> Thanks for the responses! As suggested, wrapping in 'doall' does work. >>> >>> >>> On Jun 8, 2013, at 3:28 AM, Thomas Heller <th.hel...@gmail.com> wrote: >>> >>> (defn filter-file [filename] >>> (with-open [rdr (io/reader filename)] >>> (reduce (fn [words line] >>> (->> (str/split line #"\s+") >>> (filter #(and (<= (count %) 9) >>> (>= (count %) 4))) >>> (set) >>> (set/union words))) >>> #{} >>> (line-seq rdr)))) >>> >>> >>> That code is really graceful and clean. I like it a lot. But for some >>> reason I've never loved 'reduce' before, which probably means I've never >>> used it where it is called for. Reduce just seems so generic... it's what >>> you say when you haven't got anything better to say, something like "all >>> right, do this." >>> >>> But, having said that, I'd pick your implementation over mine, because I >>> think it's conceptually cleaner (as recursive algorithms often are). Nice. >>> Thanks! >>> >>> steven >>> >>> -- >>> -- >>> 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 unsubscribe from this group and stop receiving emails from it, send an >>> email to clojure+unsubscr...@googlegroups.com. >>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >> >> >> -- >> -- >> 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 a topic in the >> Google Groups "Clojure" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/clojure/5o7iIrQQlR4/unsubscribe?hl=en. >> To unsubscribe from this group and all its topics, send an email to >> clojure+unsubscr...@googlegroups.com. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > > > -- > -- > 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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.