Patrick R. Michaud wrote:
> On Thu, Jun 05, 2008 at 05:29:25PM +0100, Daniel Ruoso wrote:
>> Qui, 2008-06-05 às 11:04 -0500, Patrick R. Michaud escreveu:
>> > Does fall back to a subroutine occur anytime we don't have
>> > a method with a matching signature? For example, if we have
>>
>> as far as I understand it, it only falls back to sub-dispach if the
>> method dispatch would otherwise fail, which basically means...
>>
>> > class Foo {
>> > multi method bar(Num $x) { say "Foo::bar"; }
>> > }
>> > sub bar(Int $x) { say "sub bar"; }
>> > my $foo = Foo.new;
>> > $foo.bar(3);
>>
>> since Num.ACCEPTS(3) should return true (rakudo is failing that), the
>> method dispatching should be successfull, therefore no fallback occurs.
>
> Okay, so my bad example didn't provide an answer to my
> original question. Let's try it this way:
>
> class Foo {
> multi method bar(Dog $x) { say "Foo::bar"; }
> }
> sub bar(Int $x) { say "sub bar"; }
>
> my $foo = Foo.new;
> $foo.bar(3);
>
> In this case, since Foo has a bar method (but not one matching Int),
> do we still fall back to the subroutine call?
We can't, because the subroutine call takes the invocant as the first
positional argument. If it should fall back (and I don't know if it
does), you have to declare sub bar(Foo $w, Int $x){ say "sub bar" }
> How about if the method
> isn't a multimethod (or if the sub is a multisub)?
>
> Pm
--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/