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

Re: WTF? - Re: method calls on $self

Thread Previous | Thread Next
From:
Rick Delaney
Date:
July 14, 2005 14:33
Subject:
Re: WTF? - Re: method calls on $self
Message ID:
20050714213547.GH19090@localhost.localdomain
On Thu, Jul 14, 2005 at 01:39:44PM -0700, Larry Wall wrote:
> On Thu, Jul 14, 2005 at 12:55:26PM -0400, Nathan Gray wrote:
> : So long as .foo (pretty please) means $_.foo all the time (with sugar on
> : top?).
> 
> It means that all the time, but only when unambiguous.  If you say

If .method always means $_.method ($_ being the topic) then I don't see how
it is ever ambiguous.  Unless I missed where nested loops would also
disallow .method because people might not be able to keep track of the
topic.

>     use dot;
> 
> it'll always be construed as unambigous.  You could go so far as to
> say
> 
>     method foo($x) {
> 	my $y = .bar;	# $_ is self call because $_ := $?SELF
> 
> 	given $y { use dot;	# "yes I know what I'm doing"
> 	    when 1 { .abc }	# calls $y.abc
> 	    when 2 { .bcd }	# calls $y.bcd
> 	}
> 
> 	.baz;		# back to self.baz
>     }

Why must anything special be done in the given block to allow .method if
it is always $_.method?  Since I know $y is the topic in this block I know
to expect $y.abc to be called.  There is no ambiguity.  An error here
would just be confusing.

Now, for those who want .abc to call $?SELF.abc within the given block
then I think it would be clearer if they spelled out that intention with
something like

    given $y { use dot '$?SELF'; # or just 'use dot' with suitable default
        when 1 { .abc } # calls $?SELF.abc
    }

-- 
Rick Delaney
rick@bort.ca

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