Operators

Logical operators

Full

Short-circuiting and / or / not, defined-or //, and their low-precedence words.

Raku's logical operators short-circuit and, crucially, return one of their operands rather than a plain Bool — so they double as value-selectors. There are tight symbolic forms and loose word forms.

and, or, not #

&& is logical-and, || logical-or, ! negation. In Boolean context they behave as expected.

say True && False;
say True || False;
say !True;
Output
False
True
False

They return an operand #

|| returns the first true operand (or the last), && the first false one (or the last) — the basis of the "or a default" idiom.

say 0 || "default";
say "" || "fallback";
say 42 && "reached";
Output
default
fallback
reached

Defined-or — // #

// returns its left side unless it is undefined, in which case the right. Unlike ||, a defined-but-false value (like 0) passes through.

say Any // "fallback";
say 5 // 10;
Output
fallback
5

Low-precedence words #

and, or, not are the same operations at very loose precedence — handy for control flow (open($f) or die) without parentheses.

say (1 and 2);
say (0 or 3);
say (not 0);
Output
2
3
True

Notes #