Reputation: 1202
I'm trying to overload the >> operator like this:
class A {}
multi sub infix:«>>»(A:D $a, Str() $b) is assoc<non> { dd $a; dd $b }
my $x = A.new;
$x >> 'output.txt';
But I get a compile error at line 5 that says:
Unsupported use of >> to do right shift. In Raku please use: +> or ~>.
What am I missing?
Upvotes: 9
Views: 142
Reputation: 5346
This is a case of Rakudo's compiler being (kind of) too smart for its own good. Because there are different types of shifting operations in Raku and neither use a double arrow, the grammar used by Rakudo has >>
set to trigger an alert for people who are used to other languages. I guess no one thought at the time that someone would make a >>
operator which makes sense because >>
more or less implies there might be a <<
, which could wreak all sorts of havoc given it use as a quoting circumfix and a meta operator.
You can see the code the grammar here: https://github.com/rakudo/rakudo/blob/9d6d8dd7a72aed698e30b6fe4b8eea62642c62c6/src/Perl6/Grammar.nqp#L4104
Upvotes: 6