Liste des Groupes | Revenir à cl c |
On 03/11/2024 21:00, Bart wrote:
To my mind, this is a type of "multi-way selection" :
(const int []){ a, b, c }[n];
I can't see any good reason to exclude it as fitting the descriptive phrase.
And if "a", "b" and "c" are not constant, but require evaluation of some sort, it does not change things. Of course if these required significant effort to evaluate,Or you had a hundred of them.
or had side-effects, then you would most likely want a "multi-way selection" construction that did the selection first, then the evaluation - but that's a matter of programmer choice, and does not change the terms.You still don't get how different the concepts are. Everybody is familiar with N-way selection when it involves actions, eg. statements. Because they will be in form of a switch statement, or an if-else chain.
I am very keen on keeping the concepts distinct in cases where it matters.I know, you like to mix things up. I like clear lines:
This is a program from my 1990s scripting language which was part of my CAD application:int x = if (randomfloat()<0.5) 42;In C, no. But when we have spread to other languages, including hypothetical languages, there's nothing to stop that. Not only could it be supported by the run-time type system, but it would be possible to have compile-time types that are more flexible
>
and only need to be "solidified" during code generation. That might allow the language to track things like "uninitialised" or "no value" during compilation without having them part of a real type (such as std::optional<> or a CBut you are always returning an actual type in agreement with the language. That is my point. You're not choosing to just fall off that cliff and return garbage or just crash.
It doesn't return a value. That is why it is UB to try to use that non-existent value.And why it is so easy to avoid that UB.
So, you're suggesting that "most people" would prefer a language that lets you do crazy, unsafe things for no good reason? That is, unless you prefer to fall off that cliff I keep talking about.My language will not allow it. Most people would say that that's a good thing. You seem to want to take the perverse view that such code should be allowed to return garbage values or have undefined behaviour.Is your idea of "most people" based on a survey of more than one person?
Note that I have not suggested returning garbage values - I have suggested that a language might support handling "no value" in a convenient and safe manner.But in C it is garbage. And I've show an example of my language handling 'no value' in a scheme from the 1990s; I decided to require an explicit 'else' branch, which you seem to think is some kind of imposition.
Totally independent of and orthogonal to that, I strongly believe that there is no point in trying to define behaviour for something that cannot happen,But it could for n==4.
EVERYBODY agrees that leading zero octals in C were a terrible idea. You can't say it's just me thinks that!With justification. 0010 means 8 in C? Jesus.I think the word "neighbour" is counter-intuitive to spell.
>
Once a thread here has wandered this far off-topic, it is perhaps not unreasonable to draw comparisons with your one-man language.Suppose I'd made my own hammer. The things I'd use it for are not going to that different: hammering in nails, pulling them out, or generally bashing things about.
The real problem with your language is that you think it is perfectCompared with C, it a huge improvement. Compared with most other modern languages, 95% of what people expect now is missing.
int F() {
F(1, 2.3, "four", F,F,F,F(),F(F()));
F(42);
It is undefined behaviour in C. Programmers are expected to write sensible code.But it would be nice if the language stopped people writing such things, yes?
If I were the designer of the C language and the maintainer of the C standards, you might have a point. C is not /my/ language.You do like to defend it though.
We can agree that C /lets/ people write messy code. It does not /require/ it. And I have never found a programming language that stops people writing messy code.I had included half a dozen points that made C's 'if' error prone and confusing, that would not occur in my syntax because it is better designed.
Les messages affichés proviennent d'usenet.