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

Re: Topicalizers: Why does when's EXPR pay attention to topicaliz er r egardless of associated variable?

Thread Previous | Thread Next
From:
Larry Wall
Date:
March 26, 2002 10:21
Subject:
Re: Topicalizers: Why does when's EXPR pay attention to topicaliz er r egardless of associated variable?
Message ID:
200203261819.KAA09091@wall.org
Aaron Sherman writes:
: On Thu, 2002-03-21 at 12:52, Allison Randal wrote:
: > On Wed, Mar 20, 2002 at 09:59:35AM -0800, Larry Wall wrote:
: > > 
: > > I should update y'all to my current thinking, which is that $_ is
: > > always identical to the current topic, even if the topic is aliased to
: > > some other variable. To get at an outer topic, you'd have to use the
: > > same mechanism we'll use for redeclared lexicals:
: > > 
: > >     my $foo = $OUTER::foo;
: > > 
: > >     for @x {			# aliases $_
: > > 	for @y -> $y {		# aliases both $x and $_
: > > 	    print $OUTER::_;
: > > 	}
: > >     }
: > 
: > I rather like this compromise. It provides the desired behaviour of
: > "always default to the current topic" and so eliminates the confusion
: > between C<when> and other defaulting constructs. It also maintains the
: > "$_ is default" concept, which is quite important to people, as earlier
: > bits of this thread demonstrated. 
: 
: Ok, so am I to take it that you could say:
: 
: FOO: for @x {
:   BAR: for @y {
:     print $FOO::_;
:   }
: }

Er, I don't think so.

: Or is OUTER a special-case label?

It's a special case like MY::, and somewhat ugly to discourage you from
using it when you should probably be naming your loop variables.

: Personally, I've always prefered this syntax:
: 
: for @x {----\
:   for @y {   |
:     print;<-/
:   }
: }
: 
: Which is visually appealing and raises coding style arguments to a whole
: new level.

Hmm, tempting.

Larry

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