Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: •Re: Detecting function vs method in an AUTOLOAD?

by TimToady (Parson)
on Apr 12, 2004 at 19:10 UTC ( #344483=note: print w/ replies, xml ) Need Help??


in reply to •Re: Detecting function vs method in an AUTOLOAD?
in thread Detecting function vs method in an AUTOLOAD?

From the viewpoint of Perl 5, it's a feature, but from the viewpoint of Perl 6, it's a bug. Perl 6 will distinguish AUTOMETH from AUTOSUB. (Those are the declarative forms, which return references. Perl 6 will distinguish those from the defining forms, which are spelled AUTOMETHDEF and AUTOSUBDEF, and which may only be called on predeclared (or autodeclared) names to supply a missing definition.)


Comment on Re: •Re: Detecting function vs method in an AUTOLOAD?
Select or Download Code
•Re: Re: •Re: Detecting function vs method in an AUTOLOAD?
by merlyn (Sage) on Apr 12, 2004 at 19:19 UTC
    So, there'll be ways to "fake" a method call using a subroutine call, like we have now? There'll have to be, or else you can't get Perl5 semantics inside Perl6 syntax, as promised.

    For example, this should still work, somehow:

    my $meth = $object->can("foo"); $meth->($object, $arg1, $arg2); # simulate $object->foo($arg1, $arg2);

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Even today, in Perl5, I'd write that as

      $object->$meth($arg1,$arg2);

      but it's clear that one or the other should be there, and not something ugly like

      apply($object,$method,$arg1,$arg2);
      or, assuming that can returned a bound method,
      my $meth_ref = $object->can($method); apply($meth_ref,$arg1,$arg2);
      Yes, once you've taken a reference to a method, it's essentially a sub ref at that point, so the Perl 6 equivalent of your code works as you'd expect. In fact, the standard dispatchers are defined in those terms. But the standard dispatchers will be able to keep subs and methods straight to the extent that you wish them to (which, by default, is up to the point that a method turns out to be completely missing, and you wish it to "failover" to looking for a multi-sub instead).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://344483]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-09-01 12:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (6 votes), past polls