Should the comma operator be removed in D2?

Justin Johansson no at spam.com
Mon Nov 16 16:52:15 PST 2009


grauzone wrote:
>> Note that if comma-as-sequencer was removed, and repurposed as a tuple
>> literal  (with "a,b"  making a tuple), and if we specify that tuple
>> elements are evaluated in order, then I think this would work as a
>> replacement for the current comma operator:
>>
>>   (expr1,expr2,expr3)[$-1]
>>
>> But the nice thing is you can get the effect of a comma operator that
>> evaluates to the value of any expression in the sequence, just using
>> different indices.
>> Not sure how odious people would find forcing an order of eval on
>> tuples, though.
>>
>> In the context of a for-loop, you don't care what the value is, so it
>> would work as a tuple as-is.  The tuple itself would be the value:
>>
>>   for(; i<10; ++i,++j)  // just works
> 
> That's nice.
> 
>> Though, probably this case needs some special treatment to continue 
>> working:
>>
>>   int i=0,j=0
> 
> Does it need to be a special case? "int i=0,j=0" is one declaration 
> (with variables separated by a comma), not something glued together with 
> the comma operator.
> 
> Of course normal declarations like "int i, j;" also would continue to 
> work. Not all commas are part of a comma expression.

Great. Sounds like problem solved in that there is no problem.

So how do people feel about bill's suggestion to progress the issue further?

Be good to get some comments from higher-up (Walter, Andrei)?

Predict bearophile will chime in on this one too?



More information about the Digitalmars-d mailing list