On 2008-Dec-6, at 7:37 am, Aristotle Pagaltzis wrote:
Funnily enough, I think you’re onto something here that you didn’t
even notice: [...]
if we had a NOTFIRST (which would run before ENTER just as FIRST
does, but on *every* iteration *except* the first), then we could
trivially attain the correct semantics and achieve all desired
results:
repeat {
@stuff = grep { !.valid }, @stuff };
NOTFIRST {
.do_something( ++$i ) for @stuff;
}
} while @stuff;
The really nice thing about this is that the blocks are nested, so
that any variable in scope for the invariant enforcement will also
be in scope in the NOTFIRST block without the user ever having to
arrange another enclosing scope.
Oh, yes! So what if we had "LOOP $n {}" that executed on the nth
iteration? "LOOP 0 {}" at the beginning would be like FIRST {}, "LOOP
* {}" at the end would be like LAST {}, and "LOOP 1..* {}" would give
us the NOTFIRST block. Presumably you could have multiple LOOP blocks
too.
(Actually, you couldn't quite do FIRST/LAST using LOOP $n, because
FIRST/LAST occur outside ENTER/LEAVE, whereas LOOP would occur
inside. But perhaps you could have LOOP blocks inside ENTER/LEAVE
blocks?)
-David