This is a fascinating language! I am so curious: how does the “anything goes” matcher work? I struggle to imagine how one would implement that ~~ operator.
and then method resolution (including multimethod handling, of course) figures out which ACCEPTS method to call and that does ... whatever the author of the type implemented.
('mostly' because ~~ actually aliases $lhs as $_ and passes $_ as the argument to ACCEPTS)
You probably know it well but let me elaborate a bit more "for the sake of the audience":
- the left handside is evaluated into a value (let's symbolize this value with $lhs)
- this value is passed into the expression on the right handside as the $_ (topic) variable
- the expression on the right handside gets evaluated, producing an $rhs value
- now, $rhs.ACCEPTS($lhs) is called
The funky thing is that the right handside of this operator is an expression, not an evaluated value... it's like an invisible code block. The implementation calls this property of an operator "thunkiness", the expression on one side acting like a thunk rather than something that can be evaluated right away. This is akin to the short-circuiting behavior of && and ||.