On Thu, Jul 14, 2005 at 04:31:07PM -0400, Stevan Little wrote:
: > A submethod is simply a method that says "These
: >aren't the droids you're looking for" if you call it via either SMD
: >or MMD dispatch and the first invocant isn't of the exact run-time
: >type of the lexical class.  In other words, it just has an implicit
: >
: >    next METHOD if $?SELF != $?CLASS;
: >
: >at the front.  So the dispatch continues until it finds either a 
: >submethod
: >that does have an exact match or a method that isn't a submethod.
: 
: Now, the metamodel currently does not have MMD, and  I think "next 
: METHOD" is not as relevant in SMD. So would it make sense to do:
: 
:       next SUPER if $?SELF != $?CLASS;
: 
: or something like that?

It comes out to that under single inheritance, but under MI it might
well be that the next method that ought to be called is actually a
sibling method.

: Here is some example code which might encounter this:
: 
: class Foo {
:       method baz { ... }
: }     
: 
: class Bar is Foo {
:       submethod baz { ... }
: }
: 
: class FooBar is Bar {}
: 
: my $foo_bar = FooBar.new();
: $foo_bar.baz() # calls Foo::baz()
: 
: basically the dispatch goes from  Bar::baz, which says "next SUPER" and 
: the dispatcher then goes to Foo::baz since it is a method.
: 
: Is that correct?

It says "next METHOD", which has the same effect under SI.  But we don't
know whether we're under MI, and we don't know if the dispatcher we're
working under has some weird order of visitation, so it's clearer to
say "next METHOD" and leave it up to the dispatcher to decide if the
SUPER is the next method.  It *usually* is, but...

: You refer to CREATE and BUILDALL as methods here, but A12 calls them 
: submethods. Which is correct?

The default versions are methods so that they can be inherited.  The
individual versions defined by classes are submethods unless they intend
to be inherited, and force all their subclasses into a new set of default
sematics.  And they're always called as methods (except when things like
.* cheat).

: >I believe there's pseudo-code for that in A12.  The trick is that you
: >can always force a call to a submethod of the "wrong" class by taking
: >it as a sub reference and calling it like an ordinary subroutine.
: 
: Okay, this is just as dirty a trick as sneaking up into the metamodel, 
: so I will leave it that way for now, knowing I need to change it later 
: :)

Of course, the metamodel can do whatever dirty tricks it likes,
but in Perl 6 the metamodel might actually implement this particular
operation by forcing a sub call through a reference, if the metamodel
is implemented in Perl 6.  It's the only way we've defined to
defeat the .foo dispatcher so far, from a language point of view.
(Though simply calling .meta could also be construed as cheating,
I guess.  Or at least an authorization of cheating on your behalf.)

Larry

Reply via email to