Name: Anonynus 2011-01-28 1:17
The ability to define your own operators, like in haskell, is a
very nice language feature. Perl 6 allows that too but it goes
too far. It allows you to define all kinds of weird operators (e.g., infix, postfix, prefix, postcircumfix, metaoperators ... ).
For instance there's the '=' metaoperator. It acts like the well
known '+=', '*=' etc. except it (theoretically) works for all
operators.
Some examples:
So far that's quite nice but now it gets ugly:
Here '>=' is itself an operator and thus is given priority over the '=' postfix operator.
Here it works again.
You'd probably expect this to work too but '<==' is the feed operator and takes priority.
You can also use letters in your operators:
Now whenever you introduce a new operator you have to check that you don't break any of the myriad combinations of the operators you already have (e.g., Zmax, xx=, X=>, >>== ... ).
very nice language feature. Perl 6 allows that too but it goes
too far. It allows you to define all kinds of weird operators (e.g., infix, postfix, prefix, postcircumfix, metaoperators ... ).
For instance there's the '=' metaoperator. It acts like the well
known '+=', '*=' etc. except it (theoretically) works for all
operators.
Some examples:
my $a = "foo "; # $a => "foo "
$a.chop; # $a => "foo "
$a.=chop; # $a => "foo"
my $b = "bar"; # $b => "bar"
$b => 1; # $b => "bar"
$b =>= 1; # $b => ("bar" => 1)So far that's quite nice but now it gets ugly:
my $c = 1; # $c => 1
$c >=; # $c => 1Here '>=' is itself an operator and thus is given priority over the '=' postfix operator.
$c >== 2; # $c => FalseHere it works again.
$c = 1; $c <== 2; # throws an errorYou'd probably expect this to work too but '<==' is the feed operator and takes priority.
You can also use letters in your operators:
sub postfix:<foobar> ($x) {$x + 1}
2foobar; # => 4
$c = 2; $cfoobar; # error, no such variable
postfix:<foobar> $c; # => 4Now whenever you introduce a new operator you have to check that you don't break any of the myriad combinations of the operators you already have (e.g., Zmax, xx=, X=>, >>== ... ).