re: We don't need a ternary operator VIEW POST

FULL DISCUSSION
 

As usual, the Adaist is different :-)

Ada (since 2005, I guess) has a "kind of" ternary operator that has some similarity with Ruby. In Ada you use just a "if" construct

X := (if (a > b) then 4 else 5);

If I am not wrong (I am to lazy to start the IDE and try...) you need the parenthesis around the if. I did not check thoroughly, but I think that this prevent the issues with associativity: "if" expressions have no associativity and you need parenthesis to use them. (Ada also force you to use parenthesis in expressions with both "and" and "or," in order to avoid ambiguities).

The nice part is that there is also a "case" expression

X := case day is
when Monday => 3,
When Sunday => 4,
...
end case;

They are very convenient, especially in inline functions.

code of conduct - report abuse