unj2
unj2

Reputation: 53481

Is there an alternative to map to apply a function to all in the sequence in Clojure?

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?

Upvotes: 4

Views: 581

Answers (1)

Timothy Pratley
Timothy Pratley

Reputation: 10662

doseq is precisely for this purpose.

(doseq [x xs] (side-effect x))

Upvotes: 6

Related Questions