develooper Front page | perl.perl6.language | Postings from May 2005

multi sub and invocants (related to colon question from earlier)

Thread Next
Aaron Sherman
May 17, 2005 09:27
multi sub and invocants (related to colon question from earlier)
Message ID:
There's some ambiguity in A/S 6 that I wanted to ask about.

A6 says:

        Ordinary subs never have an invocant. If you want to declare a
        non-method subroutine that behaves as a method, you should
        declare a submethod instead.

But S6 changes that without fully explaining itself:

        Multimethod and multisub invocants are specified at the start of
        the parameter list, with a colon terminating the list of

S12 sayeth:

        Ordinarily all the arguments of a multi sub are considered
        The caller indicates whether to use single dispatch or multiple
        dispatch by the call syntax. The "dot" form and the indirect
        object form default to single dispatch. Subroutine calls with
        multiple arguments and operators with multiple operands default
        to multiple dispatch.

Ok, so here we are. I'm told on #perl6 that you can't have something

	class Num {
		method abs() returns Num { ... }
	multi sub abs(Num $i:) returns Num { ... }

because you're not allowed to define both multi and single-dispatch
methods on a class.

Let's say that that's true. You can certainly still end up in conflict:

	class A {...}
	my A $a = but role { method x() {...} }
	eval 'multi sub x(A $i:) {...}';

Now, the eval should work because A has no x method, but you do now have
a $a which will conflict on $a.x

According to the above bit from S12, $a.x calls single dispatch first,
so it should call the anonymous role's method x, right?

If I wanted to call the multi, I could aways say: x($a), couldn't I?

Aaron Sherman <>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About