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

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

Thread Next
From:
Aaron Sherman
Date:
May 17, 2005 09:27
Subject:
multi sub and invocants (related to colon question from earlier)
Message ID:
1116347215.27930.5449.camel@pps
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
        invocants

S12 sayeth:

        Ordinarily all the arguments of a multi sub are considered
        invocants
        [...]
        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
like:

	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 = A.new() 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 <ajs@ajs.com>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback



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