Logic
logical operations (AND, OR, XOR, etc), helpers and constants for boolean values
Predicates
Constants
The Logic module provides boolean operations and logical value manipulation. Beyond traditional true/false operations, it includes support for ternary logic with maybe
and optimized evaluation strategies.
Key Concepts
- Three-valued logic:
true
,false
, andmaybe
- Standard boolean operations (AND, OR, XOR, etc.)
- Short-circuit evaluation for improved performance
Basic Usage
Basic Logical Values
print true? true ; true
print false? false ; true
print true? maybe ; maybe
Logical Operations
and? true true ; true
or? true false ; true
xor? true true ; false
; with maybe
and? true maybe ; maybe
or? true maybe ; true
Short-Circuit Evaluation
; if first block is false,
; the second one won't be evaluated
if and? [1=2][print "never runs"] ->
print "not true"
; if first block is true,
; the second one won't be evaluated
if or? [1=1][print "never runs"] ->
print "was true"
; was true
Note
Using blocks withand?
andor?
enables short-circuit evaluation. In a few words: blocks are only evaluated when needed.
Common Patterns
Testing Multiple Conditions
conditions: @[true false true true]
; check if all conditions are true
all? conditions ; => false
; check if any condition is true
any? conditions ; => true
Tip
Combining conditions in blocks withand?
andor?
(or more than one condition insideall?
orany?
blocks) is more efficient than checking them separately!
Advanced Logical Operations
a: true
b: false
print nand? a b ; true = not (a and b)
print nor? a b ; false = not (a or b)
print xnor? a b ; false = not (a xor b)