Booleans¶
Overview¶
The standard boolean objects for true and false are written as #t and #f. Alternatively, they can be
written #true and #false, respectively. Unlike most Scheme implementations, Cozenage displays true and false as
#true and #false by default in the REPL, however, the short and long forms are identical and interchangeable
in all contexts.
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 Cozenage values, only #f counts as false in conditional expressions. All other Scheme values, including #t, count as true.
Boolean constants evaluate to themselves, so they do not need to be quoted in programs.
--> #t
#true
--> #false
#false
Boolean procedures¶
not¶
- (not obj)
The not procedure returns
#trueif obj is false, and returns#falseotherwise.- Parameters:
obj – The object to test.
- Returns:
#true or #false.
- Return type:
boolean
Example:
--> (not #t) #false --> (not 3) #false -> (not (list 3)) #false --> (not #f) #true --> (not '()) #false --> (not (list)) #false --> (not 'nil) #false
boolean?¶
- (boolean? obj)
The boolean? predicate returns #true if obj is either #true or #false and returns #f otherwise.
- Parameters:
obj (any) – the object to test
- Returns:
#true or #false
- Return type:
boolean
Example
--> (boolean? #t) #true --> (boolean? #f) #true --> (boolean? "a string") #false
boolean=?¶
- (boolean=? obj obj ... )
The boolean=? procedure returns #true if all the arguments are booleans and all are #true or all are #false. Accepts zero or more arguments.
- Parameters:
obj (any) – the object(s) to test.
- Returns:
#true or #false
- Return type:
boolean
Example
--> (boolean=?) #true --> (boolean=? #t #t #t) #true --> (boolean=? #t #f) #false --> (boolean=? "foo" "bar" "baz") #false