On Mon, 2002-09-09 at 15:12, Luke Palmer wrote: > > Going back to patterns, this gives us an added bonus. It not only > > explains the behavior of hypotheticals, but also of subexpression > > placeholders, which are created when the pattern returns: [...] > > I think this is a very clean and simple way to get everything that > > patterns were supposed to do plus a lot of added benefit for things > > like:
> This does bring up an interesting point. I think your solution is an > interesting idea, but not really necessary. But consider this: Before we consider your concern (which I will address below), why is this "not really necessary"? As I see it, here are the needs addressed: 1. Creating lexically scoped variables in caller's namespace 2. Protecting existing lexicals from unexpected side-effects. One of those is mandated by A5, and one of those is, IMHO, requisite for maintainable programming. We also achieve the following: 1. Limiting TCL-upvar-like manipulation of caller's stack 2. Allowing "pass-through" subroutines This last bit is kind of crucial, IMHO. It makes a lot of sense to me that this would work: sub match_digits($str //= $_) { /(\d+)/ } if match_digits { print $1 } And if C<$0> contains a property that causes the lexicals to be created upon return, then it would (because match_digits just returns C<$0> to the caller). > my $date; > # lots of code > sub foo { > #lots more code > sub bar { > #lots more code > m/ $date := <date> /; > } > } If you used my suggestion, this would produce a warning or error depending on strictness. That would have to be "my volatile $date" to allow a thrown lexical to stomp it, in which case > Oh. Duh. Why don't we have such a mechanism for matches? My question exactly. There is more that you can do once you can throw lexicals. For example, you could provide a property for subroutines and rules which asserts the lexicals which it can throw: rule date is declaring($date) { # or is that declaring('date')? $date := (<parse_date>) } # or sub stat($filename//=$_) is declaring($mtime, $ctime, ...) { # ... return %statstruct but lexicals(%statstruct); } Now, the compiler can generate stomping warnings at compile-time instead of just at run time. -- Aaron Sherman <[EMAIL PROTECTED]> http://www.ajs.com/~ajs