Conditional logic selects which expressions to evaluate according to a condition. In Clojure, branching constructs are part of the language’s small, composable foundation, and every conditional form returns a value. Because unselected branches are not evaluated, conditionals can control effects as well as choose results. section 3.0 section 3.3
Choose the form that matches the shape of the decision:
- `if` and `if-not` select between two branches. Their required test expression determines whether the then or else expression runs; omitting else returns nil when that branch would run. section 3.3.1
- `when` and `when-not` conditionally run one or more expressions. They implicitly wrap those expressions in `do` and return nil when the condition does not match. section 3.3.1
- Tests accept any Clojure expression interpreted by logical truth: only `false` and `nil` are false; values such as `0`, an empty string, and an empty list are true. section 3.2
- Use the `-not` forms when the negative condition deserves direct emphasis rather than an inverted positive expression. section 3.3.1
Two-way choice and guarded work
A coin toss chooses one result without evaluating both branches: (defn toss [] (if (> 0.5 (rand)) "head" "tail")) (take 5 (repeatedly toss)) ;; ("head" "head" "head" "head" "tail") For one-sided work, `when` avoids an explicit else branch: (when s (try (.close s) (catch Exception e (println "error closing socket"))) ;; nil section 3.3.1 section 3.3.1
Table 3.1. Common Clojure values and their boolean translation
| Description |
Example |
Boolean Value |
| Number zero |
|
|
| Empty string |
|
|
| Empty list |
|
|
| List of nil |
|
|
| Nil |
|
|
Use the truth-value table to check edge cases before placing values in conditional tests. section 3.2




















