"Tim M" <[email protected]> wrote in message news:[email protected]... > > Although I don't really understand your problem or how it relates to the D > lang.
It doesn't really relate to D. Hence "[OT]" off-topic ;) But there seem to be a number of people here that are good with language theory (or at least better than me), so I thought I'd try here (in addition to other more directly relevant communities). > D and other C like languages do have if expressions too but they're just > not called if expressions. They're called ternary expressions due to the > way they have 3 blocks around single characters rather than the word 'if' > but the concept is pretty much the same. > > condition ? trueCode : falseCode Yea. And I've been starting to see why they do it that way. There's a number of things about it that make it much easier to implement. Ex. easy for the parser to distinguish from a statement, no dangling-else issue since the "else" part is never optional (And in my limited experience, the dangling-else ambiguity seems to be a *lot* easier to fix (at least without requiring extra syntax) when the if is restricted to being a statement-only), etc. One of the approaches I tried (and the one that seems to be giving me the most luck) is to treat the if-expression as much as possible like a ?: ternary operator.
