Sujet : Re: else ladders practice
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 08. Nov 2024, 23:24:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vgm33b$3c7q7$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Mozilla Thunderbird
On 08/11/2024 17:37, Janis Papanagnou wrote:
On 03.11.2024 18:00, David Brown wrote:
or using the respective alternative forms with ( a | b | c) ,
or ( a | b ) where no 'ELSE' is required. (And there's also
the 'ELIF' and the '|:' as alternative form available.)
BTW, the same symbols can also be used as an alternative form
of the 'case' statement; the semantic distinction is made by
context, e.g. the types involved in the construct.
You mean whether the 'a' in '(a | b... | c)' has type Bool rather than Int?
I've always discriminated on the number of terms between the two |s: either 1, or more than 1.
It would be uncommon to select one-of-N when N is only 1! It does make for an untidy exception in the language, but which has never bothered me (I don't think I've even thought about it until now.)
Bart, out of interest; have you invented that syntax for your
language yourself of borrowed it from another language (like
Algol 68)?
It was heavily inspired by the syntax (not the semantics) of Algol68, even though I'd never used it at that point.
I like that it solved the annoying begin-end aspect of Algol60/Pascal syntax where you have to write the clunky:
if cond then begin s1; s2 end else begin s3; s4 end;
You see it also with braces:
if (cond) {s1; s2; } else { s3; s4; }
With Algol68 it became:
IF cond THEN s1; s2 ELSE s3; s4 FI;
I enhanced it by not needing stropping (and so not allowing embedded spaces within names); allowing redundant semicolons while at the same time, turning newlines into semicolons when a line obviously didn't continue; plus allowing ordinary 'end' or 'end if' to be used as well as 'fi'.
My version then can look like this, a bit less forbidding than Algol68:
if cond then
s1
s2
else
s3
s4
end