"using the result of a comma expression is not allowed"
Dukc
ajieskola at gmail.com
Sun Apr 21 18:14:53 UTC 2024
On Sunday, 21 April 2024 at 16:28:47 UTC, Don Allen wrote:
> I just ran across "using the result of a comma expression is
> not allowed" in a situation where I used a comma expression as
> I would in C, expecting its value to be the value of the
> right-most expression.
>
> While D's language document is accurate in explaining how the
> comma expression is treated in D in 11.5, that treatment
> conflicts with 11.1:
> "Expressions are used to compute values with a resulting type.
> These values can then be assigned, tested, or ignored.
> Expressions can also have side effects."
>
> This restriction makes no sense to me, nor does calling this an
> "expression" if you can't use its value.
The comma expression used to work just like in C several years
ago. Using it's value was disallowed at some point because there
have been talks about using the syntax for something else -
tuples if I recall correctly. The idea was that this way we don't
end up changing what a syntax does overnight, it will be disabled
for a few years in between so there can be a deprecation period.
Apparently the spec wasn't corrected completely to reflect the
new rules.
It is an expression in a grammatical sense, meaning you can put a
comma expression anywhere you would put a side-effecting
expression. For example:
```D
for(;;comma(), expression()) condition?
another(), comma(), expression():
(yet(), another(), expression());
```
...well it seems the compiler rejects the conditional here
(otherwise this is fine). That's arguably a bug, after all it's
not using the result in any way.
More information about the Digitalmars-d
mailing list