Booleans - MIT/GNU Scheme 9.1
Description: MIT/GNU Scheme 9.1

Next: Symbols, Previous: Miscellaneous Datatypes, Up: Miscellaneous Datatypes

### 10.1 Booleans

The boolean objects are true and false. The boolean constant true is written as ``#t`', and the boolean constant false is written as ``#f`'.

The primary use for boolean objects is in the conditional expressions `if`, `cond`, `and`, and `or`; the behavior of these expressions is determined by whether objects are true or false. These expressions count only `#f` as false. They count everything else, including `#t`, pairs, symbols, numbers, strings, vectors, and procedures as true (but see True and False).

Programmers accustomed to other dialects of Lisp should note that Scheme distinguishes `#f` and the empty list from the symbol `nil`. Similarly, `#t` is distinguished from the symbol `t`. In fact, the boolean objects (and the empty list) are not symbols at all.

Boolean constants evaluate to themselves, so you don't need to quote them.

         #t                                      =>  #t
         #f                                      =>  #f
         '#f                                     =>  #f
         t                                       error--> Unbound variable

— variable: false
— variable: true

> These variables are bound to the objects `#f` and `#t` respectively. The compiler, given the `usual-integrations` declaration, replaces references to these variables with their respective values.

> Note that the symbol `true` is not equivalent to `#t`, and the symbol `false` is not equivalent to `#f`.

— procedure: boolean? object

> Returns `#t` if object is either `#t` or `#f`; otherwise returns `#f`.

>               (boolean? #f)                           =>  #t
>               (boolean? 0)                            =>  #f

— procedure: not object
— procedure: false? object

> These procedures return `#t` if object is false; otherwise they return `#f`. In other words they invert boolean values. These two procedures have identical semantics; their names are different to give different connotations to the test.

>               (not #t)                                =>  #f
>               (not 3)                                 =>  #f
>               (not (list 3))                          =>  #f
>               (not #f)                                =>  #t

— procedure: boolean=? obj1 obj2

> This predicate is true iff obj1 and obj2 are either both true or both false.

— procedure: boolean/and object ...

> This procedure returns `#t` if none of its arguments are `#f`. Otherwise it returns `#f`.

— procedure: boolean/or object ...

> This procedure returns `#f` if all of its arguments are `#f`. Otherwise it returns `#t`.