Larry Wall <[EMAIL PROTECTED]> 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
     }
   }

Reply via email to