Neat trick - 'with' and unnamed objects + 'with' proposals
BCS
BCS at pathlink.com
Tue Apr 24 10:57:27 PDT 2007
Dan wrote:
> Bill Baxter Wrote:
>
>> typeof(condition()) x;
>> while(x = condition()) {
>> // do stuff
>> }
>>}
>
>
> Which is frighteningly different semantically, while being almost identical syntactically to:
>
> while(x == condition()) {
>
> Which is probably why Walter didn't want it to work. It concerns me a little that if(x = 3) works.
>
> Honestly, D is syntactically abstracted away enough that while(something something) wouldn't have to compile down to evaluating it repeatedly.
>
>
if(x = 3) doesn't compile. For the If case the syntax requiters that the
type specifier be used:
if(auto x = 3) // works
if(x == 3) // works
if(x = 3) // fails
OTOH with 'wile' the third case is totally legitimate
char x;
while(x = getc()) // scan for null and use non null in loop;
actually the proposed addition would make that error less likely, in
fact the direct assignment could be banned in a while statement.
char x;
while(auto c = getc())
{
x=c; // if last c needed;
break;
}
More information about the Digitalmars-d
mailing list