Closed ChristianGruen closed 1 year ago
It’s true, it’s not the first time I’m making this suggestion (https://www.w3.org/Bugs/Public/show_bug.cgi?id=29263). As some people who took part in the old discussion were in favor of the proposal, and as users continue to ask us why else
is required in XQuery if they can omit it in so many other languages, I decided to bring this up again. But I can well understand that this is a controversial topic.
Regarding the parsing rules, it would feel quite natural to me to associate else
with the nearest if
expression. As far as I know, this is how it is done in other languages that allow else
to be omitted. I don’t know if there are any languages in which the outer expression is chosen?
If the dangling-else ambiguity is too confusing, perhaps the then
should be optional as well. One could use {}
in place of it
Then there are two ifs, one with then and else, and one with neither then nor else. I.e., if (A) { B }
would be equivalent to if (A) then (B) else ()
Another idea:
Flowers need to start with let/for. But if they were allowed without that, you could just write where A return B
Closed; see https://github.com/qt4cg/qtspecs/issues/234
The XQuery/XSLT WG made a conscious and carefully considered decision NOT to allow conditional expressions without an else branch, and it's not clear to me that the rationale has changed. The basic reason for not allowing it was to avoid the dangling-else ambiguity (
if (a) then if (b) then c else d
). It's not entirely clear how this proposal attempts to resolves this: note that the ambiguity exists at the syntactic parsing level. It's possible to define arbitrarily that theelse
is associated with the innermostif
, but (a) resolving EBNF ambiguities with informal prose rules is best avoided, and (b) half the time this is going to result in an interpretation which isn't what the user intended. And in any case, the requirement can usually be met by writingb[a]
.