manpagez: man pages & more
info guile
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6.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 Equality) and numerical and string comparison operators like string=? (see section String Comparison) and <= (see section 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 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).

In C, the two Scheme boolean values are available as the two constants SCM_BOOL_T for #t and SCM_BOOL_F for #f. Care must be taken with the false value SCM_BOOL_F: it is not false when used in C conditionals. In order to test for it, use scm_is_false or scm_is_true.

Scheme Procedure: not x
C Function: scm_not (x)

Return #t if x is #f, else return #f.

Scheme Procedure: boolean? obj
C Function: scm_boolean_p (obj)

Return #t if obj is either #t or #f, else return #f.

C Macro: SCM SCM_BOOL_T

The SCM representation of the Scheme object #t.

C Macro: SCM SCM_BOOL_F

The SCM representation of the Scheme object #f.

C Function: int scm_is_true (SCM obj)

Return 0 if obj is #f, else return 1.

C Function: int scm_is_false (SCM obj)

Return 1 if obj is #f, else return 0.

C Function: int scm_is_bool (SCM obj)

Return 1 if obj is either #t or #f, else return 0.

C Function: SCM scm_from_bool (int val)

Return #f if val is 0, else return #t.

C Function: int scm_to_bool (SCM val)

Return 1 if val is SCM_BOOL_T, return 0 when val is SCM_BOOL_F, else signal a ‘wrong type’ error.

You should probably use scm_is_true instead of this function when you just want to test a SCM value for trueness.


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

This document was generated on April 20, 2013 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.