| 104 | | =head3 What about multimethod dispatch and cases where there is more than one invocant? |
| 105 | | |
| 106 | | In the argument list (Capture), there is always zero or one invocant I<argument>. |
| 107 | | |
| 108 | | Multimethod dispatch governs cases where multiple invocant I<parameters> |
| 109 | | are declared in the parameter list (Signature); each of them may bind |
| 110 | | to the invocant argument, or one of the positional arguments. |
| | 104 | =head3 What about multi-dispatch? |
| | 105 | |
| | 106 | Multi-dispatch governs cases where multiple subroutines or methods share |
| | 107 | the same name, relying on the arity and types of tie-breaking I<parameters> |
| | 108 | in their parameter list (Signature): |
| | 109 | |
| | 110 | multi f ($x: $z) { say 'A' } |
| | 111 | multi f (Int $x, Int $y: $z) { say 'B' } |
| | 112 | multi f (Str $x, Str $y: $z) { say 'C' } |
| | 113 | |
| | 114 | f(1, 2); # goes to A |
| | 115 | f(1, 2, 3); # goes to B |
| | 116 | f('x', 'y', 'z'); # goes to C |
| | 117 | |
| | 118 | During multi-dispatch, a tie-breaking parameter may bind to the invocant |
| | 119 | argument (e.g. for multi-methods), or one of the positional arguments. |
| | 120 | |
| | 121 | However, regardless of single- or multi- dispatch, the argument list (Capture) |
| | 122 | can never have more than one invocants. Typically, the presence of an invocant |
| | 123 | indicates a method-call (which may fall back to a subroutine-call); the lack of |
| | 124 | invocant means a subroutine-call. |
| | 125 | |
| | 126 | 1.foo(2); # Int.foo with 1 as "self"; if not found, fallback to foo(1, 2) |
| | 127 | foo(1: 2); # same as above |
| | 128 | |
| | 129 | bar(1, 2); # never looks at Int.foo; calls &foo in lexical/package scope |
| | 130 | |
| | 131 | Method/subroutine calls are determined by the presence of an invocant at the |
| | 132 | calling site. Single/multi dispatch are determined by the precense of "multi" |
| | 133 | in the declaration site. The two concepts are entirely orthogonal. |