Literals & quoting
Booleans
FullTrue and False, how any value becomes Boolean, and that Bool is a number.
Bool has two values, True and False. Any value can be viewed as a Boolean — its "truthiness" — and Bool is itself an Int enum, so it participates in arithmetic.
The two values #
say True; say False; say True.Int;
Output
True
False
1Truthiness — so / ? #
so (and the prefix ?) coerces any value to Bool. Zero, the empty string, and empty collections are false; almost everything else is true.
say so 5; say so 0; say so "";
Output
True
False
FalseBool is a number #
True and False are the enum values 1 and 0, so they add up — handy for counting matches.
say True + True; say (5 > 3);
Output
2
TrueNotes #
- Because
Boolnumifies,+@matches.grep(...)or[+] @flagscounts true values directly. - Comparison and logic operators return
Bool; a bare regex match returns a truthyMatch, whichso/?collapse toTrue/False. - The negation
!and the low-precedencenotproduceBoolfrom any value:!0isTrue.