Boolean values

The standard boolean objects for true and false are written as #t and #f. Alternatively, they may be written #true and #false, respectively.

boolean ::= #t | #f | #true | #false

What really matters, though, are the objects that the Scheme conditional expressions (if, cond, and, or, when, unless, do) treat as true or false. The phrase “a true value” (or sometimes just “true”) means any object treated as true by the conditional expressions, and the phrase “a false value” (or “false”) means any object treated as false by the conditional expressions.

Of all the Scheme values, only #f counts as false in conditional expressions. All other Scheme values, including #t, count as true. A test-expression is an expression evaluated in this manner for whether it is true or false.

Note: There are plans to also treat as false the Java values #!null, and also all java.lang.Boolean instances for which booleanValue() return false (in addition to the special Boolean:FALSE instance which is already false). However, this is not yet implemented.

Note: Unlike some other dialects of Lisp, Scheme distinguishes #f and the empty list from each other and from the symbol nil.

Boolean constants evaluate to themselves, so they do not need to be quoted in programs.

#t       ⇒  #t
#true    ⇒  #t
#f       ⇒  #f
#false   ⇒  #f
'#f      ⇒  #f

Type: boolean

The type of boolean values. As a type conversion, a true value is converted to #t, while a false value is converted to #f. Represented as a primitive Java boolean or kava.lang.Boolean when converted to an object.

Procedure: boolean? obj

The boolean? predicate returns #t if obj is either #t or #f, and returns #f otherwise.

(boolean? #f)   ⇒  #t
(boolean? 0)    ⇒  #f
(boolean? '())  ⇒  #f

Procedure: not obj

The not procedure returns #t if obj is false, and returns #f otherwise.

(not #t)         ⇒  #f
(not 3)          ⇒  #f
(not (list 3))   ⇒  #f
(not #f)         ⇒  #t
(not ’())        ⇒  #f
(not (list))     ⇒  #f
(not ’nil)       ⇒  #f

Procedure: boolean=? boolean1 boolean2 boolean3 ...

Returns #t if all the arguments are booleans and all are #t or all are #f.