Overloaded operators: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: further exposition) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: more clarification) |
||
Line 93: | Line 93: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
While it is very easy to overload operators in Raku, it isn't really common... |
While it is very easy to overload operators in Raku, it isn't really common... |
||
at least, not in the traditional sense. |
at least, not in the traditional sense. Or it's extremely common... It depends on how you view it. |
||
that: "Different things should look different". It follows that "Similar things |
One of the founding principles of Raku is that: "Different things should look different". It follows that "Similar things should look similar". |
||
should look similar". |
|||
To pick out one tiny example: Adding numbery things together shouldn't be easily confusable with concatenating |
To pick out one tiny example: Adding numbery things together shouldn't be easily confusable with concatenating |
||
Line 156: | Line 156: | ||
Unicode character or combination may used to define it. They may be infix, |
Unicode character or combination may used to define it. They may be infix, |
||
prefix, postfix, (or post-circumfix!) The precedence, associativity and arity |
prefix, postfix, (or post-circumfix!) The precedence, associativity and arity |
||
are all easily defined. |
are all easily defined. An operator at heart is just a subroutine with funny calling conventions. |
||
Borrowed from the [[Nimber_arithmetic#Raku|Nimber arithmetic]] task: |
Borrowed from the [[Nimber_arithmetic#Raku|Nimber arithmetic]] task: |
||
Line 193: | Line 193: | ||
} |
} |
||
# New infix + |
# New infix + multi to add two Lines together, for some bogus definition of add |
||
multi infix:<+> (Line $x, Line $y) { |
multi infix:<+> (Line $x, Line $y) { |
||
Line.new( |
Line.new( |