Another article of the series “Yet Another Perl 6 Operator”
The design of Perl 6 includes some unification mechanisms to bring some extra power to syntax and developers. One of such artefacts is the notion of meta-operators. With them, it is possible to construct augmented operators from existing ones.
The first of such meta-operators we’re going to look at is the quite simple
'!' negation prefix.
When applied to infix operators which produce a Bool result, they build a boolean-wise negated version.
== (numeric equality) / !== (numeric inequality) eq (string equality) / !eq (string inequality) ~~ (smart match) / !~~ (smart "mismatch") < (less than) / !< (not less than)
A few of these have traditional shortcuts: like
'!=' as a synonym of
'ne' which is the same as
'!eq'. But from the point of view of homogeneity, the negated operators are more easily decipherable.
With negated relational operators, many expressions and algorithms will get a more natural code, without compromising their meaning and readability.
$x !eqv $y versus ! ( $x eqv $y )
The precedence of any negated operator is the same as the base operator. To avoid visual confusion with the
'!!' operator, it is forbidden to modify any operator already beginning with
Note. This article is an expansion of section “Negated relational operators” of Synopsis 03 .
Next article is due tomorrow (Dec 20, 2007).