Feature request: extending comma operator's functionality

Jonathan M Davis jmdavisProg at gmx.com
Thu Oct 4 17:16:00 PDT 2012

On Friday, October 05, 2012 02:08:14 bearophile wrote:
> Tommi:
> > Maybe we forget about commas then, and extend if-clauses so
> > that you can properly define variables at the beginning of it.
> > Separated by semicolons.
> Regarding definition of variables in D language constructs, there
> is one situation where sometimes I find D not handy. This code
> can't work:
> do {
> const x = ...;
> } while (predicate(x));
> You need to use:
> T x;
> do {
> x = ...;
> } while (predicate(x));

Yeah. That comes from C/C++ (and is the same in Java and C#, I believe). I 
don't know why it works that way. It's definitely annoying.

Of course, changing it at this point would change the semantics in a 
potentially code-breaking manner in that if the condition relies on any 
variables local to the loop having been destroyed, then its behavior will 
change. That's probably an insanely uncommon situation though - enough so that 
I'd be all for changing the semantics to have the scope exited _after_ the 
test is done (assuming that there's not a solid technical reason to keep it 
as-is). But I have no idea how possible it is to talk Walter into that sort of 

- Jonathan M Davis

More information about the Digitalmars-d mailing list