develooper Front page | perl.perl6.language | Postings from September 2001

Re: Multiple-dispatch on functions

Thread Previous | Thread Next
From:
Damian Conway
Date:
September 1, 2001 17:01
Subject:
Re: Multiple-dispatch on functions
Message ID:
200109020001.LAA92695@indy05.csse.monash.edu.au
Ken wrote:

   > The way to approach this problem is to profile
   > Class::MultiMethods and figure out (a) where the hot spots
   > are and (b) what core support would help eliminate those
   > hot spots.

But please don't do that until I release the next update of C::MM,
which will use a new dispatch mechanism that is pluggable.

   > The one thing I'm curious about is whether different syntactic
   > conventions affect the dispatcher or whether this is all just
   > sugar for a single dispatch. 

Multiple dispatch is certainly not (practically) implementable via single
dispatch. Oh, there *are* techniques, but they're subject to exponential
blow-out in the number of intermediate methods required to resolve all 
possible dispatches.

Syntactically, C::MM dispatches the call:

	$obj1->multimethod($obj2, $obj3);

exactly the same as:

	multimethod($obj1, $obj2, $obj3);

The only internal difference is that the first version has to do the
normal Perl single dispatch look-up before it discovers that
&multimethod is a multimethod (the second version doesn't), whilst the
second version requires that &multimethod be declared a multimethod in
the current scope (the first version doesn't).

Damian

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About