This section deals with logical values (`Booleans').
Booleans are primarily of importance as (return) values for (intrinsic) predicates. It is important to know that the truth-value of predicates is always evaluated left to right, that is, the left-most clause is evaluated first, and if that determines the value of the predicate evaluation is aborted; if not, the next clause is evaluated, etc. So, for example, if x is a Boolean, it is safe (albeit silly) to type:
> if x eq true or x eq false or x/0 eq 1 then > print "fine"; > else > print "error"; > end if;even though x/0 would cause an error ("Bad arguments", not "Division by zero"!) upon evaluation, because the truth value will have been determined before the evaluation of x/0 takes place.
The Boolean structure.
The Boolean elements.
True if both x and y are true, false otherwise.
True if x or y is true (or both are true), false otherwise.
True if either x or y is true (but not both), false otherwise.
Negate the truth value of x.
True if both x and y are true or both x and y are false, false otherwise.
True if either x is true and y is false, or x is false and y is true, otherwise false.
True if x is a Boolean value, false otherwise.
True if x is not a Boolean value, false otherwise.
Return a random Boolean.
A Boolean structure B may be used for enumeration: for x in B do, and x in B in set and sequence constructors.
> P := Booleans(); > for x, y in P do > print (x ne y) eq (x xor y); > end for; true true true trueSimilarly, we can test whether for any pair of Booleans x, y it is true that x = y iff (x ^ y) v (not x ^ not y).
> equal := true; > for x, y in P do > if (x eq y) and not ((x and y) or (not x and not y)) then > equal := false; > end if; > end for; > print equal; true