On Sat, Jan 29, 2005 at 05:59:40PM +0100, Juerd wrote:
: Some questions after reading S04:
: 
: 
: Can last/redo be used outside loops? (i.e. with if or given)

No, though of course what "loop" means is negotiable.  Effectively,
anything that captures the appropriate control exceptions is a loop.
But I think the design is best served if it's pretty well known what
an "official" loop is, much as we say what an official "sub" is so
that we know which entity is exited when you say "return".  To that end,
the control exceptions for next/last/redo may well include information
on which outer lexical scope is intended, presuming there's a surrounding
lexical scope that is the obvious target.  The p5-ish behavior of
scanning out the dynamic scopes for an appropriate label would perhaps
be a fallback if there is no appropriate lexical scope.  In other words,
if you say "next METHOD", and there's a METHOD: label in your current
sub, we should probably assume the user means that METHOD label rather
than the METHOD label on the implicit method dispatcher.

: Is a bare block still a loop?

We need a do-once loop.  Or if we don't exactly need it, it certainly
turned out to be handy in Perl 5, if only to provide a switch statement.
I think it would be surprising, though, to turn C<given> into a loop.
Plus, it has other difficulties as a do-once loop.  It requires an
argument before the closure, and it clobbers $_.  C<for 1> suffers
similarly.

So there's some argument for keeping bare {...} as a do-once loop.
It doesn't suffer the argument problems of C<given>, though it does
suffer from a bit surprising to newcomers.  But this morning it occurs
to me that if we defined C<do {...}> to be a do-once loop, it kind of
naturally rules out putting an C<until> or C<while> modifier on it,
since you then have conflicting loop specifications.  I realize that's
just a rationalization, since you could certainly define it such that
the do {...} nested inside the statement modifier.  But I'm looking
at it more from a psychological-space viewpoint here, and since we're
outlawing do-while anyway, we might as well give people a semilogical
reason for it, which they can take as a semological reason if they like.

But speaking of semology, another psychological argument in favor of
that is that the longer construct should have more semantics than the
shorter one.  That is, the marked form should do more than the unmarked
form.  Plus the simple fact that introducing loop semantics into bare
blocks at the same time as making all blocks closures potentially
introduces halting-problem-ish non-optimizabilities--how can we know
that the bare block isn't going to execute a "next" someplace in it.

So for the moment, let's say that bare block is not a loop, but a C<do>
block is.  It might provide some short-term confusion to Perl 5 programmers,
but I think the risk is worth it, unless someone can spot additional
difficulties.

: Can loop be used as a statement modifier? (say 'y' loop;)

Seems awfully obscure just to save two curlies, and I'm not sure the
fact that something is an infinite loop can ever be construed as
unimportant enough to be relegated to the right margin.

: Can OUTER be stacked? ($OUTER::OUTER::_)

Yep.  You'll note it's not a subtle construct--this is quite intentional.

: TIA.

YWIR.

Larry

Reply via email to