February 2018
Intermediate to advanced
304 pages
7h 11m
English
Clojure provides the if special form as part of the language:
| | (if (= 1 1) (println "yep, math still works today")) |
| | | yep, math still works today |
Some languages have an unless, which is (almost) the opposite of if. unless performs a test and then executes its body only if the test is logically false.
Clojure doesn’t have unless, but it does have an equivalent macro called when-not. For the sake of having a simple example to start with, let’s pretend that when-not doesn’t exist and create an implementation of unless. To follow the rules of Macro Club, begin by trying to write unless as a function:
| | ; This is doomed to fail... |
| | (defn unless [expr form] |
| | (if expr nil form)) |
Check ...