Boolean operations

Booleans

Arc provides basic Boolean operations. Only nil and empty list are false; any other value, including 0 and empty string, is true. The operations provide short-circuit evaluation, so only the necessary arguments are evaluated, left-to-right.

See also the Anaphoric operations aand and aor.

no expr
Complement: returns true if expr is false, and false if expr is true.
>(no 1)
nil
>(no nil)
t
and [arg ...]
The and boolean operator tests if all the arguments are true. It evaluates its arguments in turn until a false argument is found. If all arguments are true, the last argument is returned. If all arguments are false, nil is returned. The and operator performs 'short-circuit' evaluation, and doesn't evaluate arguments that follow a false one.
>(and 1 t 0 "x")
"x"
>(and nil t)
nil
>(and nil (/ 1 0))
nil
or [arg ...]
The or boolean operator tests if any of the arguments are true. It evaluates its arguments in turn until a true argument is found. If any argument is true, the first true argument is returned. If all arguments are false, nil is returned. The or operator performs 'short-circuit' evaluation, and doesn't evaluate arguments that follow a true one.
>(or nil 42 '() (/ 1 0))
42
>(or nil '())
nil
nor [arg ...]
The nor boolean operator tests if all of the arguments are false. It returns t if all arguments are false, and nil if any arguments are true. It performs 'short-circuit' evaluation, and doesn't evaluate arguments that follow a true one.
>(nor nil nil)
t
>(nor nil 1 (/ 1 0))
nil

Copyright 2008 Ken Shirriff.