Sujet : Re: else ladders practice
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 06. Nov 2024, 00:01:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vge84o$1o57r$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Mozilla Thunderbird
On 05/11/2024 20:33, David Brown wrote:
On 05/11/2024 20:39, Waldek Hebisch wrote:
David Brown <david.brown@hesbynett.no> wrote:
On 05/11/2024 13:42, Waldek Hebisch wrote:
Bart <bc@freeuk.com> wrote:
>
Then we disagree on what 'multi-way' select might mean. I think it means
branching, even if notionally, on one-of-N possible code paths.
>
OK.
>
I appreciate this is what Bart means by that phrase, but I don't agree
with it. I'm not sure if that is covered by "OK" or not!
>
You may prefer your own definition, but Bart's is resonable one.
The only argument I can make here is that I have not seen "multi-way select" as a defined phrase with a particular established meaning.
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)
Where again one of these elements is evaluated, selected by n (here having the values of 1, 2, 3, ... compared with true, false above, but there need to be at least 2 elements inside |...| to distinguish them).
I applied it also to other statements that can be provide values, such as if-elsif chains and switch, but there the selection might be different (eg. a series of tests are done sequentially until a true one).
I don't know how it got turned into 'multi-way'.
Notice that each starts with an assignment (or the value is used in other ways like passing to a function), so provision has to be made for some value always to be returned.
Such N-way selections can be emulated, for example:
if (c)
x = a;
else
x = b;
But because the assignment has been brought inside (a dedicated one for each branch), the issue of a default path doesn't arise. You can leave out the 'else' for example; x is just left unchanged.
This doesn't work however when the result is passed to a function:
f(if (c) a);
what is passed when c is false?