May 2018
Beginner to intermediate
290 pages
6h 43m
English
Being able to branch on an explicit true or false is only half of what makes if the programming workhorse that it is. The other half is being able to ask the questions that evaluate to a Boolean. Probably the most common question we ask in programs is Does this thing equal this other thing? Happily, the Clojure equality-testing function has a very obvious name.
It’s just a single equals sign:
| | (= 1 1) ; True! |
| | |
| | (= 2 (+ 1 1)) ; True again! |
| | |
| | (= "Anna Karenina" "Jane Eyre") ; Nope. |
| | |
| | (= "Emma" "Emma") ; Yes! |
Like + and *, the = function looks like an operator but is really just a function. And like + and *, the = function will take any number of arguments:
| | (= (+ 2 2) 4 (/ 40 10) (* 2 2) (- 5 1)) ; True! |
Read now
Unlock full access