On Mon, Apr 29, 2002 at 10:10:01AM -0400, Aaron Sherman wrote:
> On Fri, 2002-04-26 at 19:06, Allison Randal wrote:
>
> Absolutely what I thought. "elsif" would be for "thing else if" where
> "elsfor" would be "thing else for-loop". Since you got this distinction
> right off, it sounds like an intuitive enough syntax.
I'll vote with the others on this. The meaning is only partially
intuitive when you read it. You'll notice that I thought *you* meant
that "elsfor" would be an "else" (i.e. a conditional) tacked onto a
C<for>. And as far as using it, I'd rather not memorize (and teach)
dozens of "compound keywords" and all their subtle nuances when simple
control structures will do.
> So, this should not be confusing either:
>
> $i=0;
> loop ;$i<$max;$i++ { ... } else { ... }
>
> In this case, if $max <= 0, then you will execute the else.
I agree.
> Again, it's just first derivative over time. You're not asking "is there
> a false value", you're asking "is the loop false". Just as we understand
> that an array in a conditional context is false if it is empty, so too
> is a loop false if it is "empty". This is a basic Perl concept, and it
> makes sense to promote it from static arrays to more dynamic loops.
I agree again.
There will have to be a section of the training material devoted to
"When is a loop false?" (I like that perspective, it nicely unifies the
cases), but it should be a short one.
> > But the aliased value, $_, is restricted to the scope of the C<while>'s
> > block, it isn't going to be accessible in the block associated with the
> > C<else> (you would be getting some $_ from an outer scope).
>
> You're thinking of loops in a curious and convoluted way, Try this out:
>
> { loop-keyword [ conditional/declaration ]
> block
> { else-clauses ...} }
>
> The loop itself comprises an outer scope in which the conditionals or
> declarations exist. Then, each block comprises a sub-scope. In this way,
> there is no confusion, no special case, no violation of the rules.
Not so much convoluted as literal-minded on lexical scope being tied to
blocks: { {} } is not the same as { } { }. It could be made to work, but
it would be an exception to Perl's general take on lexical scope.
> It becomes reasonable now to have:
>
> for @a -> $b {
> stuff using $b
> } elsfor @c -> $d {
> more stuff using $b and $d
> } else {
> yet further stuff with access to $b and $d
> }
>
> And what a neophyte programmer might expect about access to variables is
> all true.
Except that, as Damian pointed out, if the C<for> is "false" $b will
never be aliased at all.
Allison