Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

perl 6 craziness

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:

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 => 1

Here '>=' is itself an operator and thus is given priority over the '=' postfix operator.

$c >== 2; # $c => False

Here it works again.


$c = 1; $c <== 2; # throws an error

You'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; # => 4


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=>, >>== ... ).

Name: Anonymous 2011-01-28 1:47

>>1
Perl
goes too far

POLECAT KEBAGS

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List