tags:

views:

98

answers:

1

I have a function

(defn change-score [docid termid]
    (do (dosync (alter *documents-scores* assoc docid  (+ 1 (*documents-scores* docid))))
      nil)  )

(defn vector-space[]
    (loop [terms (count (deref *term-hash*))]
     (if (zero? terms)
         nil
         (do
          (dorun (map (fn[docid](change-score docid terms)) (doc-list terms)))
          (recur (dec terms))))))

Is there an alternative to map in the function?

+4  A: 

doseq is precisely for this purpose.

(doseq [x xs] (side-effect x))
Timothy Pratley
As somebody who's just started looking at Clojure (and liking it a lot), I have to say that the linked documentation for doseq is not that clear. Is it referring to how things are done in the for form? If so, the doc for that one could be better, too (best thing about for's doc is the example.)
Anon
Yup, there is a wiki with examples which you might find handy:http://en.wikibooks.org/wiki/Clojure_Programming/Examples/API_Examples/do_Macros#doseq
Timothy Pratley