Re: Clarification on S12
Qui, 2008-06-05 às 15:43 -0700, Larry Wall escreveu: > Maybe it's just a temporary lack of imagination, but I'm having trouble > these days coming up with any kind of a use case for confusing single > dispatch with multiple dispatch. Yeah, I know I wrote that, but I was > either smarter or stupider back then... Let me try... :) { class Foo { method bar(Num $a) {...} } sub bar(Foo $f, Str $b) {...} Foo $f .= new; # This would dispatch the method bar $f.bar(1); # should it fallback? even if method bar is not multi? $f.bar("Hello"); } I think it could be resumed to the following truth table: For $f.bar("hello") does it fallback? method| sub| fallback? multi | multi | yes multi | single | yes? single| multi | no? single| single | no? My initial idea was that it would allways fallback if the method dispatch fails. Which would mean that this belongs to the interpreter dispatcher, not to the object dispatcher (what makes sense, since you need lexical information to do this). If that is not the case, there are two options: 1) There are two failure types for the object dispatch, which would trigger or not the fallback... 2) The object dispatcher is the one responsible for doing the fallback (using CALLER:: to find the sub. I personally think option 2 is the the uglyiest one in terms of implementation... daniel
Re: Clarification on S12
On 2008 Jun 5, at 18:43, Larry Wall wrote: Maybe it's just a temporary lack of imagination, but I'm having trouble these days coming up with any kind of a use case for confusing single dispatch with multiple dispatch. Yeah, I know I wrote that, but I was either smarter or stupider back then... p5 backward compatibility? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH
Re: Clarification on S12
On Thu, Jun 05, 2008 at 11:04:52AM -0500, Patrick R. Michaud wrote: : This message is looking for a clarification/confirmation. : S12:207 says: : : > To call an ordinary method with ordinary method-dispatch semantics, : > use either the dot notation or indirect object notation: : > : > $obj.doit(1,2,3) : > doit $obj: 1,2,3 : > : > If the method was not found, it will fall back to a subroutine call : > instead, with the invocant becoming the first positional argument. : : Does fall back to a subroutine occur anytime we don't have : a method with a matching signature? For example, if we have Maybe it's just a temporary lack of imagination, but I'm having trouble these days coming up with any kind of a use case for confusing single dispatch with multiple dispatch. Yeah, I know I wrote that, but I was either smarter or stupider back then... Larry
Re: Clarification on S12
On Thu, Jun 05, 2008 at 10:45:08PM +0200, Moritz Lenz wrote: > > 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" } You're correct, my examples suck today. Sorry about that. The "I don't know if it does" part of your answer is the crux of my question. Essentially, does having _any_ 'bar' multimethod in a class automatically suppress a fall back to a subroutine call, even if none of the multimethods' signatures match? Pm
Re: Clarification on S12
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/
Re: Clarification on S12
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? How about if the method isn't a multimethod (or if the sub is a multisub)? Pm
Re: Clarification on S12
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. daniel