Maps associate keys with values. Keywords are the most common keys. A keyword looks itself up. get takes a fallback for a missing key.
get
(def person {:name "Ada" :born 1815}) (println (:name person)) (println (get person :city "unknown"))
assoc, dissoc, and update return a new map. keys returns the keys. Sorting them makes the print order stable.
assoc
dissoc
update
keys
(println (assoc person :city "London")) (println (dissoc person :born)) (println (update {:n 1} :n inc)) (doseq [k (sort (keys person))] (println k (get person k)))
Map literals print between braces.
$ glj maps.glj Ada unknown {:name Ada, :born 1815, :city London} {:name Ada} {:n 2} :born 1815 :name Ada
Next example: Sets.
A hands-on tour in the style of Go by Example. Glojure is a Clojure interpreter hosted on Go.