Should the comma operator be removed in D2?
Ellery Newcomer
ellery-newcomer at utulsa.edu
Mon Nov 16 16:57:13 PST 2009
Bill Baxter 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.
I wouldn't mind.
you'd also have to swap the precedence of assignment and comma, or
a,b = b,a;
isn't going to do anything useful. But then you can't have
foo(a = b);
unless the entire argument list is a tuple. But then you'd have to
change {something or another} or you can't have nested tuples.
backing up, assuming you don't allow unpareth'd tuples, then what is
( exp )
? Is it a tuple, or a scalar?
I think my personal preference at the moment would be to have tuples of
the form
(, exp , exp ... )
>
> 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
for should be a special case
More information about the Digitalmars-d
mailing list