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 <janfrider...@googlemail.com> 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 as > variables for the loop? > > (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 my-words) (merge-with + word-map {(first my-words) > 1}))))) > > Regards and thank's to all who gave (us|me) yet another reason to use > the JVM, Jan -- 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 To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.