Perl 6 Perl 6 #18

Operator overloading

Programmers may overload existing operators or define new ones:

sub postfix:<!>(Int $n) {
    if ($n < 2) { return 1; }
    return $n * ($n-1)! ;
}

sub prefix:<±>($x) {  return (+$x | -$x); }

sub infix:<(c)> ($x, $y) {
    return "$x is copyright by $y";
}
Copyright © 2008 Patrick Michaud