Peter Haworth wrote:
> Dan Sugalski wrote:
> > Adriano wrote:
> > >
> > >I think what Jonathan asked for was an operator for 
> > >returning a method (as an object) which can be invoked
> > >later with some arguments (or even applied with a
> > >partial list of arguments for currying). 
> > >
> > >This would be a lot more useful than a yes-or-no
> > >answer about the existence of a method.

Exactly. 'Yes' might be valid one moment, and invalid the next. Not a very
useful operation... Returning a coderef on the other hand is useful.


> > I thought about this--it's what the find_method vtable 
> > method was for in the first place. Unfortunately, as
> > was pointed out to me, there's no good way to cache
> > the result, since it could potentially be wrong by the
> > time the method is actually called.
> 
> Is that such a big deal? The same problem exists in perl 5 with the
> following code:
> 
>   if(my $meth=$obj->can($action)){
>     # Stuff could happen here which redefines the method in 
>     # $obj's class However, I know it won't get redefined
>     # because I wrote the whole system
>     $obj->$meth();
>   }else{
>     die "Some custom error message or appropriate action";
>   }

I don't see it as a problem. In Perl5, you get back a coderef. And despite
whether the method is modified or removed from the class in the meantime,
that code reference is still valid. Sure, if you want to garrauntee you'll
get the "appropriate" method implementation at a given instance in time,
you'll have to code a bit more carefully, but at least you know the method
implementation you've got isn't going to be changed out from under you. 

I'm not sure I follow the talk of invalidating method handles. I'm sure
there's some use for method handles. But I hope a reference to method's
implementation isn't going to run the chance of being invalidated before its
called.

I realize with Perl6 we'll have the possiblity of multi-method dispatch. But
my assumption based on Damian's posts to perl6-language is that Perl6's
->can will support passing some form of parameter list specification so that
it'd be possible for ->can to resolve the dispatch and return a coderef to
the implementation before you actually invoke it.

--
Garrett Goebel
IS Development Specialist

ScriptPro                   Direct: 913.403.5261
5828 Reeds Road               Main: 913.384.1008
Mission, KS 66202              Fax: 913.384.2180
www.scriptpro.com          [EMAIL PROTECTED]
 

Reply via email to