Changes for clojure.core/update-in

shuaybi on Tue, 10 May 2011
(defn char-cnt [s]
  "Counts occurence of each character in s"
  (reduce
    (fn [m k]
      (update-in m [k] (fnil inc 0)))
  {}
  (seq s)))
;Note use of fnil above - returns 0 if nil is passed to inc (avoids null pointer exception)
shuaybi on Tue, 10 May 2011
;Occurrences of each character in s
;Note use of fnil - returns 0 if nil is passed to inc
(defn char-cnt [s]
  (reduce
    (fn [m k]
      (update-in m [k] (fnil inc 0)))
  {}
  (seq s)))