On Jun 17, 1:22 am, Wrexsoul <d2387...@bsnow.net> wrote: > On Jun 17, 12:44 am, Parth <parth.malwan...@gmail.com> wrote: > > > > > > > On Jun 17, 9:34 am, Wrexsoul <d2387...@bsnow.net> wrote: > > > I'm shocked that this is missing from clojure.core: > > > > (defn accum [f init coll] > > > (loop [x init c coll] > > > (if (empty? c) > > > x > > > (recur (f x (first c)) (rest c))))) > > > > user=> (accum + 0 [1 2 3]) > > > 6 > > > user=> (accum + 0 [1 2 3 4 5]) > > > 15 > > > > This is one of the most basic, useful functions in functional > > > programming. :) > > > > Here's any triangular number: > > > > (defn tri [n] (accum + 0 (take n (iterate inc 1)))) > > > Maybe "apply" can be used > > > user=> (apply + [1 2 3]) > > 6 > > user=> (apply + [1 2 3 4 5]) > > 15 > > Yes, in the specific case of + it can, or other functions already > defined to take arbitrary arguments and accumulate them. > > > or "reduce"? > > user=> (reduce + 0 [1 2 3]) > > 6 > > user=> (reduce + 10 [1 2 3]) > > 16 > > user=> (reduce + 0 [1 2 3 4 5]) > > 15 > > Well that's weird. I SPECIFICALLY did a search of the entire api docs > to see if there was anything like "accum" already in there. I examined > every occurrence of "seq" and turned up a blank. > > The docs definitely have problems if this can be missed despite a very > thorough search. The only more-thorough search would have been to > actually read the docs in their entirety, rather than to search them! You are off to a bad start here on the group, and I'd advise that you change your tone significantly. Are you here to complain? If so, please take it somewhere else. If you couldn't find something you thought for sure should be there, you could have gotten an answer in seconds from the helpful people here or on the IRC. They, and I, want to help each other (and you!) be productive. What you are doing here is not contributing to that, not for yourself nor for others. I don't appreciate it, nor do the others who work on or with Clojure. Rich --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---