megan-zk
analysis

True, False, and Boolean Expressions in Clojure

Truthiness and falsiness**

Nil and false represent logical falsiness. Any value that isn’t falsey is truthy. You can check if a value is nil (or falsey) using the nil? operand:

(nil? 1) returns false because 1 is not nil (nil? nil) returns true because nil is nil

Boolean expressions will treat values as truthy or falsey. The equality operator (“=”) will evaluate if operands are equal (in other words, use “=” when evaluating truth rather than truthiness).

Boolean operators

(or false nil 1 2 3)

(or false nil)

(and 1 2 nil 3 false)

(and 1 2 3)

see also

references

  1. Higginbotham, Daniel. Clojure for the Brave and True Learn the Ultimate Language and Become a Better Programmer. Daniel Higginbotham, 2015, [https://www.braveclojure.com/clojure-for-the-brave-and-true/].