On Fri, 20 Sep 2002, Brent Dax wrote:
: Larry Wall:
: # That binds the dynamically surrounding $_ to $x as an 
: # out-of-band parameter.  Can also bind to $_ to make it the 
: # current topic.
: 
: The problem I have with that is this:
: 
:       sub for_trace(*@array, &block) {
:               loop($_=0; $_ < @array; $_++) {
:                       print "$_:\n";
:                       
:                       {
:                               my $coreprint=&CORE::print;
:                               my $lastnl=1;
:                                               
:                               temp &CORE::print := sub ($fh: *@args) {
:                                       $fh.$coreprint("\t") if $lastnl;
:                                       
:                                       $fh.$coreprint(@args);
:                                       
:                                       $lastnl = @args[@args.last] =~
: /\n $/;
:                               }
:                       
:                               block(@array[$_]);
:                       }
:                       
:                       print "\n"
:               }
:       }
:       
:       $_="x";
:       @list=qw(y z);
:       
:       for_trace @list -> $x {
:               print $_;
:       }
: 
: Which of these does this print?
: 
:       0:
:               0
:       1:
:               1
: 
:       0:
:               y
:       1:
:               z
: 
:       0:
:               x
:       1:
:               x
: 
: The "correct" behavior (IMHO) is the third, though I could see the
: second.  But the first is unacceptable.

The rule says the innermost topicalizer wins, and pointy sub always
topicalizes its first argument, so the second behavior is what happens.

The third behavior can always be forced with $OUTER::_.  But it would
be better stylistically to name it something other than $_--which is
part of the reason we decided to make the topicalizers always alias
$_ in addition to whatever else they might alias.  It's much better
to keep the pronouns referring to small-scale topics rather than
large scale.

Larry

Reply via email to