Smylers wrote:
Thom Boyer wrote:
The primary advantage, to my mind, in using C<elsif>, is that it
eliminates the dangling-else ambiguity -- so splitting it in half
removes almost ALL the value of even having an C<elsif> keyword.

Surely it's the compulsory braces, even with a single statement, which
eliminates that problem?
Almost. The compulsory-braces rule [a Perl 5 syntax decision I applaud] means that

if test1 {
statement_A;
} elsif test2 {
statement_B;
} elsif test3 {
statement_C;
}

is equivalent in meaning to

if test1 {
statement_A;
} else {
if test2 {
statement_B;
} else {
if test3 {
statement_C;
}
}
}

So if "elsif" becomes "else" followed by "if" in the scanner, the result is syntactically wrong _because_ the curly braces are required (a point that I missed in my earlier post):

if test1 {
statement_A;
} else if test2 { # syntax error: missing open brace after 'else'
statement_B;
} else if test3 { # Oops, I did it again
statement_C;
}

And let's not anybody say, "Well, 'elsif' gets converted to 'else' followed by '{' followed by 'if', then!", because that doesn't work. All the closing right curly braces would still be missing.

So the compulsory curly braces make for a much more convincing argument against an "elsif" --> "else if" conversion in the scanner.


Personally, I don't think anybody should be working this hard to make if/elsif/elsunless/else writeable as a subroutine. I don't think it should be put in that pigeonhole: it doesn't fit there very well.

If we really need the comfort of knowing that if/else/etc. is writable in Perl 6, then we can all take comfort that it _is_ always possible (if not as convenient) using the much more general grammar-extension mechanism.
=thom

Reply via email to