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?
In C++, we can change the way operators work for user-defined types like objects and structures. This is known as operator overloading. For example, Suppose we have created three objects c1 , c2 and result from a class named Complex that represents complex numbers.
Operator overloading is a compile-time polymorphism in which the operator is overloaded to provide the special meaning to the user-defined data type. Operator overloading is used to overload or redefines most of the operators available in C++. It is used to perform the operation on the user-defined data type.
Physical Data Design Considerations. Polymorphism: Polymorphism (or operator overloading) is a manner in which OO systems allow the same operator name or symbol to be used for multiple operations. That is, it allows the operator symbol or name to be bound to more than one implementation of the operator.
C++ provides a special function to change the current functionality of some operators within its class which is often called as operator overloading. Operator Overloading is the method by which we can change the function of some specific operators to do some different task.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With