Skip to content

Commit 09da192

Browse files
committed
Prefer alter-var-root over def
1 parent 3e4ce90 commit 09da192

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,23 @@ pairwise constructs as found in e.g. `let` and `cond`.
529529
...)
530530
```
531531

532+
* <a name="alter-var"></a>
533+
Use `alter-var-root` instead of `def` to change the value of a var.
534+
<sup>[[link]](#alter-var)</sup>
535+
536+
```Clojure
537+
;; good
538+
(def thing 1) ; value of thing is now 1
539+
; do some stuff with thing
540+
(alter-var-root #'thing (constantly nil)) ; value of thing is now nil
541+
542+
;; bad
543+
(def thing 1)
544+
; do some stuff with thing
545+
(def thing nil)
546+
; value of thing is now nil
547+
```
548+
532549
* <a name="nil-punning"></a>
533550
Use `seq` as a terminating condition to test whether a sequence is
534551
empty (this technique is sometimes called *nil punning*).

0 commit comments

Comments
 (0)