www.delorie.com/gnu/docs/guile/guile_168.html   search  
 
Buy GNU books!


Guile Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1 Booleans

The two boolean values are #t for true and #f for false.

Boolean values are returned by predicate procedures, such as the general equality predicates eq?, eqv? and equal? (see section 24.1 Equality) and numerical and string comparison operators like string=? (see section 21.4.7 String Comparison) and <= (see section 21.2.8 Comparison Predicates).

 
(<= 3 8)
=>
#t

(<= 3 -3)
=>
#f

(equal? "house" "houses")
=>
#f

(eq? #f #f)
=>
#t

In test condition contexts like if and cond (see section 26.2 Simple Conditional Evaluation), where a group of subexpressions will be evaluated only if a condition expression evaluates to "true", "true" means any value at all except #f.

 
(if #t "yes" "no")
=>
"yes"

(if 0 "yes" "no")
=>
"yes"

(if #f "yes" "no")
=>
"no"

A result of this asymmetry is that typical Scheme source code more often uses #f explicitly than #t: #f is necessary to represent an if or cond false value, whereas #t is not necessary to represent an if or cond true value.

It is important to note that #f is not equivalent to any other Scheme value. In particular, #f is not the same as the number 0 (like in C and C++), and not the same as the "empty list" (like in some Lisp dialects).

The not procedure returns the boolean inverse of its argument:

Scheme Procedure: not x
C Function: scm_not (x)
Return #t iff x is #f, else return #f.

The boolean? procedure is a predicate that returns #t if its argument is one of the boolean values, otherwise #f.

Scheme Procedure: boolean? obj
C Function: scm_boolean_p (obj)
Return #t iff obj is either #t or #f.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003