Sujet : Re: else ladders practice
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 06. Nov 2024, 11:01:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vgfepe$22j2u$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 06/11/2024 07:26, Kaz Kylheku wrote:
On 2024-11-05, Bart <bc@freeuk.com> wrote:
Well, it started off as 2-way select, meaning constructs like this:
>
x = c ? a : b;
x := (c | a | b)
>
Where one of two branches is evaluated. I extended the latter to N-way
select:
>
x := (n | a, b, c, ... | z)
This looks quite error-prone. You have to count carefully that
the cases match the intended values. If an entry is
inserted, all the remaining ones shift to a higher value.
You've basically taken a case construct and auto-generated
the labels starting from 1.
It's a version of Algol68's case construct:
x := CASE n IN a, b, c OUT z ESAC
which also has the same compact form I use. I only use the compact version because n is usually small, and it is intended to be used within an expression: print (n | "One", "Two", "Three" | "Other").
This an actual example (from my first scripting language; not written by me):
Crd[i].z := (BendAssen |P.x, P.y, P.z)
An out-of-bounds index yields 'void' (via a '| void' part inserted by the compiler). This is one of my examples from that era:
xt := (messa | 1,1,1, 2,2,2, 3,3,3)
yt := (messa | 3,2,1, 3,2,1, 3,2,1)
Algol68 didn't have 'switch', but I do, as well as a separate case...esac statement that is more general. Those are better for multi-line constructs.
As for being error prone because values can get out of step, so is a function call like this:
f(a, b, c, d, e)
But I also have keyword arguments.