Skip to content

Commit f78c003

Browse files
committed
echoing Postel's Law
1 parent 97f3443 commit f78c003

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

content/guides/destructuring.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ If you want it to be an error to supply a map that is missing certain keys (rath
346346
;= throws Missing required key: "dob"
347347
----
348348

349-
If you have keys you want to require but don't need to bind, you can list them after `&`, which will check for the presence of the listed keys but not create bindings.
349+
If you have keys you want to require but don't need to bind, you can list them after `&`, [since 1.13] which will check for the presence of the listed keys but not create bindings.
350350

351351
[source,clojure]
352352
----
@@ -357,9 +357,9 @@ If you have keys you want to require but don't need to bind, you can list them a
357357
(let [{:syms! [fred ethel lucy & 'ricky]} m] ...
358358
----
359359

360-
You can also document additional optional keys that you are not binding in the (:keys, :strs, and :syms) directives using `&`. [since 1.13]
360+
You can also document additional optional keys that you are not binding in the (`:keys`, `:strs`, and `:syms`) directives using `&`.
361361

362-
To pass along or inspect the effective values (input or default) bound during destructuring, bind them to a map with `:select`. [since 1.13] It includes every key used anywhere in the form, including nested forms, but not keys used only in `:or`.
362+
When you receive an input map, you often don't know exactly what it contains. To manage that uncertainty, Clojure developers often lock down the set of legal keys that their input maps accept, which creates brittle connections across system boundaries. When you need to know the keys you're dealing with or passing data to something that's intolerant of additional keys, while remaining flexible about what a process accepts, you can use `:select` [since 1.13]. The `:select` directive names a map that is a subset of the input map augmented by the defaults, limited to the the keys mentioned in the destructuring form.
363363

364364
[source,clojure]
365365
----

content/reference/special_forms.adoc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ In all of the sequential cases the __binding-form__s in the destructure binding
286286
[[associative-destructuring]]
287287
=== Associative destructuring
288288

289-
Map __binding-form__s create bindings by looking up values in collections like maps, sets, vectors, strings, and arrays (the latter three have integer keys). It consists of a map of __binding-form->key__ pairs, each __binding-form__ bound to the value in the _init-expr_ at the key provided. In addition, and optionally, an `:as` key in the binding form followed by a symbol binds that symbol to the entire __init-expr__. Also optionally, an `:or` key in the binding form followed by another map may be used to supply default values for some or all of the bindings if their keys are not found in the __init-expr__:
289+
Map __binding-form__s create bindings by looking up values in collections like maps, sets, vectors, strings, and arrays (the latter three have integer keys). It consists of a map of __binding-form->key__ pairs, each __binding-form__ bound to the value in the _init-expr_ at the key provided. In addition, and optionally, an `:as` key in the binding form followed by a symbol binds that symbol to the entire __init-expr__. To supply default values for keys that are not present in the input map, you can use the `:or` directive, whose value is a map of binding names or [since 1.13] keys to default values.
290290

291291
[source,clojure]
292292
----
@@ -296,13 +296,6 @@ Map __binding-form__s create bindings by looking up values in collections like m
296296
->[5 3 6 {:c 6, :a 5}]
297297
----
298298

299-
To supply a default for a key that has no local binding name, use the input key itself in the `:or` map instead. [since 1.13]
300-
301-
[source,clojure]
302-
----
303-
(let [{a :a, b :b, :or {:c 42}} ...
304-
----
305-
306299
To capture the default values stated in the `:or` map for some purpose later in your code without restating them, you can use the `:defaults` directive [since 1.13], which binds a name to a map, created during destructuring, of keys to their default values.
307300

308301
[source,clojure]
@@ -368,16 +361,16 @@ Clojure 1.9 adds support for directly destructuring many keys (or symbols) that
368361
-> [1 2]
369362
----
370363

371-
You can ensure that required keys are present during map destructuring by using the checked variants of the `:keys`/`:syms`/`:strs` binding directives named `:keys!`/`:syms!`/`:strs!`, which throw an exception if any of the specified keys are missing from the destructured map. [since 1.13] These checked directives also accept `&`, after which you may list additional keys that are still required and checked, but not bound to a local name.
364+
You can ensure that required keys are present during map destructuring by using the checked variants of the `:keys`/`:syms`/`:strs` binding directives named `:keys!`/`:syms!`/`:strs!`, [since 1.13] which throw an exception if any of the specified keys are missing from the destructured map. These checked directives also accept `&`, [since 1.13] after which you may list additional keys that are still required and checked, but not bound to a local name.
372365

373366
[source,clojure]
374367
----
375368
(let [{:keys! [fred ethel lucy & :ricky]} m] ... ;; m must have keys :fred, :ethel, :lucy, and :ricky
376369
----
377370

378-
In the unchecked directives `:keys`, `:strs`, and `:syms`, `&` serves only as documentation: the listed keys are neither bound nor checked for presence. [since 1.13] The literal keys after `&` may be heterogeneous, as in `:keys [a & :b "c" 'd]`, but note that symbols must be quoted to distinguish them from binding names.
371+
To document keys that you don't bind or to include them in `:select`, you can list them after `&` [since 1.13] in `:keys`, `:strs`, `:syms`. The literal keys after `&` may be heterogeneous, as in `:keys [a & :b "c" 'd]`, but note that symbols must be quoted to distinguish them from binding names.
379372

380-
To bind a name to a deep subset of the input map, augmented by defaults, use the `:select` directive. [since 1.13] It includes every key used anywhere in the destructuring form, including nested forms, but not keys used only in `:or`.
373+
When you need to know the keys you're dealing with or passing data to something that's intolerant of additional keys, while remaining flexible about what a process accepts, you can use `:select` [since 1.13]. The `:select` directive names a map that is a subset of the input map augmented by the defaults, limited to the the keys mentioned in the destructuring form.
381374

382375
[source,clojure]
383376
----

0 commit comments

Comments
 (0)