Next: Conditionals, Up: Program structure [Contents][Index]
The standard boolean objects for true and false are written as #t
and #f
.
Alternatively, they may 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 “proper 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.
In addition the null value #!null
(in Java written as null
)
is also considered false. Also, if you for some strange reason create a
fresh java.lang.Boolean
object whose booleanValue()
returns false
, that is also considered false.
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
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 kawa.lang.Boolean
when converted to an object.
The boolean?
predicate returns #t
if obj
is either #t
or #f
, and returns #f
otherwise.
(boolean? #f) ⇒ #t (boolean? 0) ⇒ #f (boolean? '()) ⇒ #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
Returns #t
if all the arguments are booleans and all are #t
or all are #f
.
Next: Conditionals, Up: Program structure [Contents][Index]