Combining conditions
and, or, not, xor — written out in full, and only on bool values.
One question is rarely enough. Archon combines several with four words.
@entry(start)
object MyProgram {
start() {
var age := 42;
var registered := true;
if (age >= 18 and registered) {
Console.print(text: "may vote");
}
if (not registered) {
Console.print(text: "still to register");
} else {
Console.print(text: "already registered");
}
}
}
Four words, written out in full
| written | true when |
|---|---|
a and b | both are true |
a or b | at least one of the two is true |
not a | a is false |
a xor b | exactly one of the two is true |
There is no &&, no ||, no !: the logical operators are written the way they are read.
The exclamation mark stays reserved for !=, and nothing else — which is what makes it
recognisable at a glance.
xor is the least common of the four: it is true when the two answers differ. “One or the
other, but not both.”
Only on bool values
Like the condition of an if, these four words accept nothing but bool values. age and registered is refused when age is a number — it takes a comparison, something that gives back
an answer: age >= 18 and registered.
It is the same rule as in 3.2, one step further out, and for the same reason: a number is not an answer to a question.
Reading a compound condition
if (age >= 18 and registered) {
The comparison happens first, the and after — >= binds tighter than and, the way * binds
tighter than + in arithmetic. So you do not have to bracket each comparison. Where a doubt
remains, parentheses are allowed and make the intent explicit.
Your turn
- Set
registeredtofalse: the first condition falls, the second changes branch. - Replace
andwithorand predict the output before running. - Write
if (age and registered)— with no comparison. The refusal names the typeandexpects, and says in its own way that a condition is built from answers, not from numbers. - Try
xorbetweenregisteredand a secondboolvariable of your choosing, and check that it is false when both are true.