"using the result of a comma expression is not allowed"

Don Allen donaldcallen at gmail.com
Mon Apr 22 13:21:41 UTC 2024


On Sunday, 21 April 2024 at 23:32:21 UTC, Timon Gehr wrote:
> On 4/21/24 21:16, Don Allen wrote:
>> And I think it's bad practice to support a hobbled version of 
>> a common construct in anticipation of a use of the same syntax 
>> that hasn't happened yet and has been in the pipeline for 
>> years.
>
> That is just one part of the rationale (that is probably on top 
> of people's mind now as there has been some recent movement on 
> tuples).
>
> https://dlang.org/deprecate#Using%20the%20result%20of%20a%20comma%20expression
>
> In any case, I don't understand why you focus on the tuple use 
> case.

Excuse me. I am an ordinary user of D (you know, the kinds of 
people the project would like to attract? One way to torpedo that 
is to behave like an OpenBSD developer), not someone who has 
participated in, or followed the history of, the language's 
development. I focused on tuples because it came up repeatedly in 
the responses to my original post. You note that yourself above. 
So I don't understand why you didn't understand.

  The main reason the comma operator was restricted was to
> avoid accidental uses. Freeing up the syntax for something that 
> is actually useful is just a nice side effect.
>
>> I am also not about to re-write my code using lambdas. It's 
>> hackish workaround for a defect in the language, in my opinion.
>
> There are many ways to write any given piece of code and the 
> variant with the comma operator is hardly ever the best one.

You haven't seen the situation where I attempted to use it as I 
would have in C, have you?

>
>> I think this was a mistake in C and a bigger mistake in D, 
>> since we know more now about language design than when Dennis 
>> Ritchie designed C about 55 years ago.
>
> One of the things we know now is that comma expressions were a 
> bad design of syntax. We should probably just have something 
> like `let statement in expression` expressions instead.

You may have missed my point, which was that value-returning 
block expressions are a better way than comma expressions to 
allow multi-statement sequences to provide a value, as in Rust:

````
let foo:i64 = if predicate
               {
                stmta1;
                stmta2;
                expra1
               }
               else
               {
                stmtb1;
                stmtb2;
                exprb1
               };
````
Something similar exists in Zig, though I don't think their 
syntax is as elegant as Rust's in this case.



More information about the Digitalmars-d mailing list