Things that may be removed

Yigal Chripun yigal100 at gmail.com
Wed Dec 24 15:55:32 PST 2008


Jarrett Billingsley wrote:
> On Wed, Dec 24, 2008 at 5:24 PM, Yigal Chripun<yigal100 at gmail.com>  wrote:
>> why not replace the current comma operator with tuple support?
>> the comma op needs to be higher than assingment in precedence and instead of
>> evaluating the expressions left to right and returning the value of the
>> _last_ expression as the return value of the op, return _all_ expressions'
>> return values as a value tuple. the current behavior that is really used
>> only in for loops can be implemented with tuples as well.
>>
>> insted of:
>> for (int i = 0, long j = 0; ...; ...) {...}
>
> Actually that's not legal syntax.  You're thinking of "int i = 0, j =
> 0", which is parsed as a single declaration statement which declares
> two variables.  This does not use the comma operator.
>
> The place where the comma operator is used is in the increment:
>
> for(..; ..; i++, j++)
>
> All that has to be done here is the comma has to be added to the
> increment grammar of the for loop.  (MiniD does this.)

and what if I do instead:
int i; long j;
for (i = 0, j = 0; ...; ++i, ++j) {...}
that should be legal, right? I don't use this feature that often....

I was trying to suggest a more general solution rather than adding a 
special case for "for" loops. IMO, with proper tuple support you do not 
need special cases. i.e.:
(++i, ++j) is a regular tuple that given i = 2 and j = 5 will evaluate 
to (3, 6) which can be assinged to the loop variable:

for (Tuple!(int, long) (a, b) = (0, 1); cond; (++a, ++b)) {...}



More information about the Digitalmars-d mailing list