Heh, I've long disliked the "invisible" block around Perl if() constructs. It belies the term "lexical scope" to me. I resolved this dislike by mostly refusing to declare lexicals inside of conditional expressions.
This reminds me of my long-standing frustration with the adamant, unconditional localization of loop variables. Default localization of loop variables seems a wise choice but there have been far too many times where part of my purpose in looping over some values was to pick one of them. And you can't do that "the obvious way" in Perl. You get the relatively awkward:
my $selected;
for my $candidate ( ... ) {
$selected= $candidate;
last
if ...;
}
localization of loop variables preceeded 'my' so, given the time-machine-like oportunity of Perl 6 breaking backward compatability in a backward-compatible way, I'm tempted to propose that "for my $foo (" continue to effectively localize (by creating a new lexical $foo) but change "my $foo; ...; for $foo (" to leave the last looped value in $foo. But, of course, that gets the Huffman coding backward and is convoluted enough to be unwise.
I re-read the section of a4 about 'foreach' and didn't see this mentioned. So I'm assuming localization is still unconditional. It makes me long for an alternative to avoid the localization. But having "for @choices -> my $chosen {" serve that purpose doesn't scratch the itch as well as I'd like and also leaves too many scratch marks.
But maybe you've already designed a better way to do this (and probably described it and I've probably read the description and either forgotten it or not understood the implications of it :). Perhaps "reusing" a variable name from the current lexical scope as a formal parameter should mean that this variable is actually used as the one that the parameter is bound to and the (last) bound parameter value is left in that variable. In the short time I've considered that idea, and with so little of the rest of Perl 6 swapped in, I think I might like that idea.
|