Disallowing ?:?: syntax

BCS ao at pathlink.com
Mon Jan 5 08:38:00 PST 2009


Reply to Miles,

> bearophile wrote:
> 
>> My little proposal for D is to turn the following into a syntax
>> error, to avoid possile programmer mistakes (so the programmer must
>> put parentheses here to make it compile):
>> 
>> x ? y : a ? b : c
>> 
> The ternary operator is not ambiguous,

I think not.

x ? y : a ? b : c => (x ? y : a) ? b : c

or

x ? y : a ? b : c => x ? y : (a ? b : c)


without checking the actual syntax you can't tell which of the above will 
be used and (according to bearophile) if ?: followed after +/-/etc the first 
would be.

> I see no need for making it an
> error. I have used such constructs very often, with no problem:
> 

However I agree. Don't change it.

> writefln("Printer is %s.",
> status == OFFLINE      ? "offline"      :
> status == ONLINE       ? "online"       :
> status == CHECK        ? "out of paper" :

> status == ONLINE_CHECK ? "on fire"      :

ha ha ha :)

> "unknown status");
> That would become a real mess of parenthesis.
> 





More information about the Digitalmars-d mailing list