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

Re: .method == $self.method or $_.method?

Thread Previous | Thread Next
From:
Piers Cawley
Date:
March 28, 2005 22:04
Subject:
Re: .method == $self.method or $_.method?
Message ID:
m2y8c7xa1h.fsf@obelisk.bofh.org.uk
Larry Wall <larry@wall.org> writes:

> I've been thinking about this in my sleep, and at the moment I think
> I'd rather keep .foo meaning $_.foo, but break the automatic binding
> of the invocant to $_.  Instead of that, I'd like to see a really,
> really short alias for $self.  Suppose we pick "o" for that, short
> for "object".  Then we get self calls of the form:
>
>     o.frobme(...)


I really, really don't want to see .foo meaning anything but $_.foo, so how
about arranging things so that the invocant becomes $_ iff you don't give it a
name. So:

   method whatever {
     # $_ is whatever's invocant
   }

   method whosit ($self:) {
     # $_ is unbound, so:
     .this # fails
     ...
   }

Note that this would also work for mappy things with pointy subs used to name
arguments.


   method whatever {
     map { .this } .list_of_contents; # Works, but is weird...
     map -> $x { .do_something_with($x.result) } # .do_something uses the
                                                 # method's invocant.
   }

Same applies to given:

   method foo {
     given .parent -> $p {
       ... # $_ is foo's invocant
     }

     given .parent {
       ... # $_ is the result of calling .parent
     }
   }


Thread Previous | 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