Hmmm... some discussion generated on this subject, but fairly light. I
take that as an indicator that an C<else> on loops is a fairly popular
idea. The other possibilities are that b) people don't want any form of
"else" on loops and aren't saying so or c) people simply don't care,
but silence and apathy just don't seem to be vices we're afflicted with
in this community. ;)

My confession for the day is: I actually like the if-like C<else>
blocks on loops. But attacking a problem from an alternate angle is a
valuable exercise. In this case:

Taking this perspective made me realize that there is a significant
semantic difference between the various new uses of C<else>.  But, in
linguistic terms, it is a perfectly valid to have a range of meaning
associated with a word (I mean related senses, not homophones or
homographs, e.g.  think of as many uses as you can for the noun
"handle"), the human brain is well adapted to it. Still, it will need to
be taught, or at least glossed-over-with-full-conciousness-that-
it's-being-glossed-over, like the semantic difference between C<if>
statements and C<if> modifiers.

I also realized that there is a chance for user error in expecting
certain values to be accesible outside their scope in the C<else> block.
But, I'd rather teach (and use) a clear, well defined, unchanging rule
of scope than a handful of exceptions any day.

As I was talking to Damian, he came up with a compelling semantic
argument why we would want C<else> blocks to follow, which is a question
that needed to be faced since we rejected C<continue>. But he should be
posting not too long after me (allow for time zone differences), so I
won't steal his thunder (well, not too much anyway :).

And the discussion of scope led to (what I think is) an interesting
tidbit on NAMED blocks (duplicate comment on thunder).

BTW, a few nails in the coffin I didn't mention: having an C<else> and
an C<ELSE> is confusing. It's bad enough that we have C<last> and
C<LAST>, etc., at least the lowercase keywords there don't have
associated blocks.

And something just feels right about C<else> blocks on loops. It fits in
with that Perlish pattern of allowing structures that feel so natural
you wonder why no other language ever allowed them.

Allison

Reply via email to