Re: using reduce instead of loop recur

2011-06-01 Thread Jonathan Fischer Friberg
Maybe not what you're looking for, but this is my take on this particular problem: (defn rem-dup [str] (->> str (partition-by (partial = \space)) (map #(if (= (first %) \space) \space %)) flatten)) I find partition-by the 'weapon of choice' when a sequence contains valu

Re: using reduce instead of loop recur

2011-05-31 Thread Ken Wesson
On Tue, May 31, 2011 at 3:45 PM, iz bash wrote: > > thanks everyone!! that was really great help. You're welcome. Hopefully, reading and understanding the code posted here (not just mine) will both get you a better grasp of the various ways these kinds of things can be tackled using HOFs like ma

Re: using reduce instead of loop recur

2011-05-31 Thread iz bash
thanks everyone!! that was really great help. -- 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 u

Re: using reduce instead of loop recur

2011-05-31 Thread Stuart Campbell
For this particular case, you could also use regexps: user> (require '[clojure.string :as s]) nil user> (s/replace " bb cc" #" +" " ") " bb cc" Regards, Stuart On 31 May 2011 08:15, iz bash wrote: > so clojures like my first programming language. most of the time > now ,i

Re: using reduce instead of loop recur

2011-05-30 Thread George Bennett
On May 30, 6:15 pm, iz bash wrote: > how'd you implement it using only higher order functions? > (rem-dup "                  bb cc")  =>    [\a \a \a \a \space \b \b > \space \c \c] (defn rem-dup [stri] (->> stri (partition-all 2 1) (filter (partial apply not= \space)) (map fir

Re: using reduce instead of loop recur

2011-05-30 Thread Ken Wesson
On Mon, May 30, 2011 at 11:29 PM, Alan Malloy wrote: > (filter identity (map f xs)) is more clearly written as (keep f xs), > unless you're relying on the former to retain false (not nil) elements. Eh -- filter identity doesn't retain false: => (filter identity [false nil 42 "foo" []]) (42 "foo"

Re: using reduce instead of loop recur

2011-05-30 Thread Alan Malloy
On May 30, 7:56 pm, Ken Wesson wrote: > On Mon, May 30, 2011 at 6:15 PM, iz bash wrote: > > so clojures like my first programming language. most of the time > > now ,i use map /reduce/.. with lazy sequences  but sometimes i just > > cant seem to find a solution other than using loop-recur. then i

Re: using reduce instead of loop recur

2011-05-30 Thread Ken Wesson
On Mon, May 30, 2011 at 6:15 PM, iz bash wrote: > so clojures like my first programming language. most of the time > now ,i use map /reduce/.. with lazy sequences  but sometimes i just > cant seem to find a solution other than using loop-recur. then i read > somewhere almost all loop recur situati

using reduce instead of loop recur

2011-05-30 Thread iz bash
so clojures like my first programming language. most of the time now ,i use map /reduce/.. with lazy sequences but sometimes i just cant seem to find a solution other than using loop-recur. then i read somewhere almost all loop recur situations can be translated into reduce. so ive posted a functi