The "|" is a logical OR separating the various cases and as such should
only appear between clauses and not precede the first one.
It is inconsistent to put this "|" phantom in
and then fault trailing ";".
On Tuesday, 30 August 2016 18:22:01 UTC+9, Martin Brown wrote:
The "|" is a logical OR separating the various cases and as such should only appear between clauses and not precede the first one.
PIM and ISO define the | within CASE statements as case label separators.
Initially, we went along with the concept of using separators and
we considered to use double-semicolons as case label separators.
This would have freed up the | for use as a replacement for OR which
in turn would have allowed consistent use of symbols as logical operators, removing reserved words AND, OR and NOT. Our rationale was: either all are symbols or all are reserved words, not both, not mixed.
However, considering the principle of least surprise, we eventually
decided against double-semicolons and removed the & and ~ as synonyms
for AND and OR instead.
Yet, while we had been looking for an alternative for | as case label separator, we felt that the ideal symbol would be a bullet and that
this ought to be a prefix, not a separator:
I am pretty confident this is what Wirth would have designed had he
had a bullet symbol at his disposal[1].
Our primary driver to switch from case label separator to case label
prefix was readability when the CASE statement spans multiple lines
which is the vast majority of use cases.
CASE x OF
| a : ...
| b : ...
| c : ...
END;
In fact this had already been a discussion point at meetings of the
ISO M2 working group. Many of the delegates felt that a prefix was
more readable and a compromise was reached to allow both variants.
Since we don't like to have alternative variants of syntax,
we decided in favour of prefixes and against separators.
[1] Unfortunately, the good people on the ASCII committee decided
to waste 33 code points on control codes .... Due to this
shortsightedness, there wasn't any space left for a bullet in the
ASCII set.
Hope this clarifies.
IIRC, one or two compilers I tried (PIM, not ISO) didn't like '|' before
the first choice. Those may have been old PIM2, though.
Wasn't ":=" supposed to represent the left arrow? So why not go all out? (Personally, I abhor that, I prefer old-fashioned ASCII.)
I am pretty confident this is what Wirth would have designed had he
had a bullet symbol at his disposal[1].
Maybe so, but he changes his mind a lot.
They also allowed '!' instead [of '|'], right? (Unlike PIM.)
So use '.' or '*' instead. Don't a lot of markup languages use the
asterisk for that?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 468 |
Nodes: | 16 (2 / 14) |
Uptime: | 19:46:06 |
Calls: | 9,440 |
Calls today: | 3 |
Files: | 13,594 |
Messages: | 6,109,830 |