develooper Front page | perl.perl6.language | Postings from April 2003

Re: S6 multimethod invocants

Thread Previous | Thread Next
From:
Damian Conway
Date:
April 13, 2003 17:20
Subject:
Re: S6 multimethod invocants
Message ID:
3E99FEA8.2090009@conway.org
Austin Hastings wrote:

>>     method foo($self, Point $p :)       {...}
>>     method foo($self, int $x, int $y :) {...}
> 
> 
> As A6 currently stands, that won't work -- only multi's are capable of
> having multiple invocants:
> 
> multi foo(Foo $self, Point $p) {...}   
> multi foo(Foo $self, int $x, int $y) {...}  # No colon means invoke ALL

Correct.

You can have two or more multimethod variants of a given name, but only one 
method of a given name (in a given namespace).


>>Or are method variants different from multimethod variants?

Yes. The former don't exist. ;-)


Just to clarify:

	* Methods have exactly one invocant, and are dispatched solely on the
	  basis of the run-time type of that invocant.

	* Multimethods can have one or more invocants, and are dispatched
	  solely on the basis of the run-time types of all their invocants.

	* Both methods and multimethods can also have non-invocant parameters
	  (declared after the colon), but the corresponding arguments take no
	  part in the dispatch process.


Thus calls to the multimethod &foo:

	multi foo(Window $w,      Event $e      : Mode $m) {...}
	multi foo(Window $w,      Str   $e_name : Lode $l) {...}
	multi foo(Str    $w_name, Event $e      : Wode $w) {...}

only consider their first two arguments when selecting which variant to invoke.

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