May 2018
Beginner to intermediate
290 pages
6h 43m
English
If vars are all about providing the global, stable environment for your code, you might wonder why vars are mutable. After all, Clojure loves immutability. But we can def and re-def our vars with wild abandon. The answer is as simple as it is pragmatic: mutable vars make for more productive Clojure programmers. Most Clojure programming is done in some form of REPL or other. So while developing, we might start out by creating a couple of vars:
| | user=> (def PI 3.14) |
| | #'user/PI |
| | |
| | user=> (defn compute-area [diameter] |
| | #_=> (* PI diameter diameter)) |
| | #'user/compute-area |
and then realize that we need more precision:
| | user=> (def PI 3.14159) |
| | #'user/PI |
and we also got the calculation wrong:
| | user=> (defn |
Read now
Unlock full access