Next: Pairs and lists, Previous: Numbers, Up: Standard procedures [Index]
The standard boolean objects for true and false are written as #t
and #f
. Alternatively, they can be written #true
and
#false
, respectively. 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.
Note: Unlike some other dialects of Lisp, Scheme distinguishes #f
and the empty list 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 #f ⇒ #f '#f ⇒ #f
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
The boolean?
predicate returns #t
if obj is either
#t
or #f
and returns #f
otherwise.
(boolean? #f) ⇒ #t (boolean? 0) ⇒ #f (boolean? '()) ⇒ #f
Returns #t
if all the arguments are
#t
or all are #f
.
Next: Pairs and lists, Previous: Numbers, Up: Standard procedures [Index]