Массивы и коллекции / Словари

(def dic {1 "A" 2 "B"})

(def value1 (get dic 3))
; value1 is nil — a missing key is not an error here

; the third argument of get is the value to give back instead
(def value2 (get dic 3 "-"))
; value2 is "-"

; fnil wraps a function so that a nil coming in becomes a default:
; (fnil inc 0) means "increment, and treat a missing count as 0"
(def char-counts
  (reduce (fn [m c] (update m c (fnil inc 0))) {} "ABCBA"))
; char-counts is {\A 2, \B 2, \C 1}

(println "value1 is" (pr-str value1))
(println "value2 is" (pr-str value2))
(println "char-counts is" (pr-str char-counts))