On Tue, 2002-04-30 at 13:07, Miko O'Sullivan wrote:
> > Damian, now having terrible visions of someone suggesting C<elswhen> ;-)
> 
> Then may I also give you nightmares on: elsdo, elsdont, elsgrep, elstry ...

Aaron, trying hard not to be a crackpot, but getting the impression
that's now just a dream :-/

If we all agree that the meaning of "els<flow-control-keyword>" is
clear, but we dislike adding insane numbers of keywords to the language,
let's step back and ask why it would have ever occurred to us to do such
a silly thing.

Since the beginning of this discussion, I've been happy to accept the
idea that "elswhile" is ugly and unmanageable, but I saw no other way,
given the if/elsif syntax.

I do think that unifying the if/loop syntax is wildly useful, but
there's no reason that we HAVE to put the burden on the loop constructs.

Why do we use "elsif"? Well, it seemed like the right choice at the
time, and avoided C's infamous ambiguity by allowing braces without
bogging down the programmer (Larry, jump in if that wasn't the
reasoning, it's been nearly a decade since I last saw you discuss the
topic).

What would happen if we had:

        if expr {
                ...
        } else if expr {
                ...
        } else {
                ...
        }

Not as a naked (i.e. un-braced) statement, but if "else if" were treated
as a single token (either at the tokenizer level or gathered together in
the parser, it doesn't really matter).

In this case, you could have all of the funky control structures you
want, but the user does not have to play string-concatenation games in
their head.

It's reasonably obvious what:

        unless my $fh=$x.open {
                die "Cannot open $x: $!";
        } else while $fh.getline -> $_ {
                print;
        } else {
                die "No lines to read from $x";
        }

would mean, and it's also a pleasingly simple addition.

Then if you want "else when" or "else do", you're all set. It's an easy
change and there are no new keywords.

I think "else grep" would be pointless, as grep is not a flow-control
structure as such. You can always "else if grep {...} list { ... }"

This also resolves the long-standing question: why isn't there an
"elsunless", which has been asked since as long as I've been programming
in Perl. I see no reason for there not to be "else unless", does anyone
else? unless?


Reply via email to