Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Methods vs. Subs

6 views
Skip to first unread message

Jonathan Lang

unread,
Jul 8, 2006, 10:42:06 AM7/8/06
to perl6language,
Is there anything that you can do with a sub (first parameter being
some sort of object) that you cannot do with a method? Frex, given:

multi method my_method($invocant:);

would

&topical_call := &my_method.assuming :invocant<$_>;

be legal?

--
Jonathan "Dataweaver" Lang

Larry Wall

unread,
Jul 8, 2006, 12:58:00 PM7/8/06
to perl6language,
On Sat, Jul 08, 2006 at 07:42:06AM -0700, Jonathan Lang wrote:
: Is there anything that you can do with a sub (first parameter being

: some sort of object) that you cannot do with a method? Frex, given:
:
: multi method my_method($invocant:);
:
: would
:
: &topical_call := &my_method.assuming :invocant<$_>;
:
: be legal?

Yes, it's certainly legal, but it's not quite the same semantics.
A sub guarantees at compile time exactly which routine is going to
be called. Your example would need a ::= to do that. But even with
that it doesn't really guarantee which my_method you're going to get,
in the sense that .assuming is going to have to do a partial method
dispatch, and which method it finds will depend on the value of $_.
Furthermore, ::= would force that to mean the compile-time value of
$_, which is probably not what you want anyway.

As far as I can figure, there's no way of defining topical_call such
that it knows to .assume $_ as its invocant without actually evaluating
$_ at the time .assuming is called, since .assuming doesn't merely
set the default; it's a partial dispatch, and throws away the assumed
parameter slot entirely from the viewpoint of the subsequent caller.
It may well have to keep track of the slot for implementation,
however--as a partial dispatch, &topical_call may in fact represent a
set of remaining candidates to be multi dispatched, and merely setting
one parameter with .assuming shouldn't imply that that's the entire
eventual parameter list. That is, it mustn't assume that the supplied
parameters are delimited with semicolons in the receiving signature.
So for purposes of implementation, it does behave merely like a default.
Go figure...

Larry

0 new messages