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

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

Thread Next
From:
Michael G Schwern
Date:
March 17, 2005 00:17
Subject:
.method == $self.method or $_.method?
Message ID:
20050317065236.GA18272@windhund.schwern.org
There's a discussion going on #perl6/irc.freenode.org right now wondering
about what .method means.  We'd all assumed it meant $self.method (where
$self is always the method invocant) but then had a look at Synopsis 12 
which states 

  Dot notation can omit the invocant if it's in $_:

    .doit(1,2,3)

This seems to cripple .method's usefulness by coupling it to $_ which
can change often.  Now in order to be safe for anything but trivial methods 
you're back to writing out $self all over the place, something that Perl 6 
was supposed to fix about Perl 5.

It has also been pointed out that .foo, $.foo, @.foo and %.foo are all
(intentionally) similar and all but one operates on the invocant.  Only
.foo operates on $_.  This seems like a newbie trap waiting to happen.
MOST of the time .foo will work like $self.foo but every once in a while
they'll get caught in a gotcha.

Thoughts?

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