Skip to content

Un-idiomatic introduction of update #34

Open
@daveliepmann

Description

@daveliepmann

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. The assoc function can be used by assigning a new value to
the existing key.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions