Re: Beginning Clojure. Recursion

2010-03-26 Thread Matthias von Rohr
(require 'clojure.contrib.seq-utils) (defn word-count [s] (frequencies (re-seq #"[a-zA-ZöäüÖÄÜß]+" s))) (word-count "foo bar baz quux quux foo") ; {"quux" 2, "baz" 1, "bar" 1, "foo" 2} Matt On Mar 25, 4:09 pm, jfr wrote: > Thanks I will take a look at it .Neverless, the idea was to write my

Re: Beginning Clojure. Recursion

2010-03-25 Thread jfr
Ok, I just looked at "frequencies" as Miki suggested. (reduce #(assoc %1 %2 (inc (get %1 %2 0))) {} ["One" "Two" "Two" "Three" "Three" "Three"]) would be more like it. Thanks for the infos... -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post

Re: Beginning Clojure. Recursion

2010-03-25 Thread jfr
Thanks I will take a look at it .Neverless, the idea was to write my own code ;-) > You can also use "frequencies" from c.c.seq-utils (http:// > richhickey.github.com/clojure-contrib/seq-api.html#clojure.contrib.seq/ > frequencies) > > HTH, > -- > Miki -- You received this message because you ar

Re: Beginning Clojure. Recursion

2010-03-25 Thread Jarkko Oranen
jfr wrote: > Hello, > > I've just started to play a little bit with clojure to get a feel for > the language. It seems to be quite interesting (and it's a relief to > leave my clumsy IDE behind and use Emacs). Concerning immutable data: > Is the following code ok or should (must) I use transients

Re: Beginning Clojure. Recursion

2010-03-24 Thread Miki
Hello, > (defn count-words [words] >   "Counts the occurrences of all words in the given string. Returns a > map with the words as keys, their frequency as values" >   (loop [my-words (re-seq #"[a-zA-ZöäüÖÄÜß]+" words) word-map {}] >     (if (empty? my-words) >       word-map >       (recur (rest

Re: Beginning Clojure. Recursion

2010-03-24 Thread ataggart
Looks fine. The maps are immutable, but the 'word-map symbol is rebound on each loop to the map returned from merge-with. On Mar 24, 2:15 pm, jfr wrote: > Hello, > > I've just started to play a little bit with clojure to get a feel for > the language. It seems to be quite interesting (and it's a

Beginning Clojure. Recursion

2010-03-24 Thread jfr
Hello, I've just started to play a little bit with clojure to get a feel for the language. It seems to be quite interesting (and it's a relief to leave my clumsy IDE behind and use Emacs). Concerning immutable data: Is the following code ok or should (must) I use transients as variables for the lo