Open
Description
In outline/data_structures.md, the section on updating maps is not idiomatic Clojure:
(def hello {:count 1 :words "hello"})
(update hello :count inc)
;=> {:count 2, :words "hello"}
(update hello :words str ", world")
;=> {:count 1, :words "hello, world"}
This is all technically true, but extremely misleading. A reasonable person would expect hello
to then be the "updated" version returned from update
, but it's not. Not only is this not explained, but it's weird and unnecessary to def
a name then update
it anyway. This is a major trap for newcomers to write non-idiomatic Clojure, yet we're explicitly teaching it!
We even say the word "save"!
After the creation [of the map], we want to save a new value associated to the
key. Theassoc
function can be used by assigning a new value to
the existing key.