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

Re: How do I... invoke a method reference

Thread Previous
From:
TSa
Date:
May 20, 2005 11:49
Subject:
Re: How do I... invoke a method reference
Message ID:
428E313D.1090105@orthogon.com
C. Scott Ananian wrote:
> I think Ingo was trying to explicitly specify the normally-implicit 
> invocant; ie, invoke the method via the reference *without* using a '.'.
> If this is possible (and I think it is), it's not (yet) clear what the
> syntax would be.  Maybe
>     $ref(Foo.new():)

I think for MMD calls no : is needed. The dispatcher should find the best
match for the complete set of args anyway. The problem is to hit the
intended recipient when there's no argument other than $_ which was just
recently re-instated as the default invocant. Even though a simple $ref.()
might know from the type of $ref which is 'Ref of Method of Foo', to
invoke a method on $_, I would expect a type error unless $_ happens to 
refer to a subtype of Foo.

Since Ingo's simple example doesn't need an invocant at all the following
might work

   class Foo
   {
      method bar(Any:) { 42 }
      method baz() { &bar }
   }

But I think it's better to make &bar a sub.
-- 
TSa (Thomas Sandlaß)


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About