Comma operator = broken design

Robert Jacques sandford at jhu.edu
Fri Dec 9 17:18:36 PST 2011


On Fri, 09 Dec 2011 01:20:45 -0500, Kagamin <spam at here.lot> wrote:

> On Thursday, 8 December 2011 at 17:18:57 UTC, Joshua Reusch wrote:
>>
>>> Ahem. So are you suggesting that (a,b) means a tuple
>>> everywhere but in a
>>> for loop, where it is used to separate two statements?
>>
>> If we use the comma operator only for tuples, there needn't to
>> be a special case for loops:
>>
>> for(x, y = 0 , 100; x < y ; x, y += 1,-1) { ... }
>
> for(int x, y = 0 , 100; x < y ; x, y += 1,-1) { ... }
>
> ?
>

Here's how I understood it:

int x,y; // Defined somewhere in the code above

for( (x,y) = (0,100); x < y ; (x,y) += (1,-1) ) { ... }

So you have variable capture, assignment and add-assign happening.


More information about the Digitalmars-d mailing list