Other ternary operations than conditional expression

377 views Asked by At

I read on Wikipedia that there are often only one ternary operation type possible in C-like languages, which is the conditional expression.

I am trying to find out what other ternary operation exists and what language would make use of them.

1

There are 1 answers

0
MvG On BEST ANSWER
  • Some languages have ternary or even variadic comparison operators, so you can write things like “0 <= x < 15”.
  • I wonder whether things like “<expression> for <variable> in <list>” from python could be considered a ternary operator as well. If you argue that the variable name in there is not an expression, then you could use the “<expresstion> for <variable> in <list> if <condition>” where expression, list and condition are arbitrary expressions. The specification lists generator expressions in the same section as most operators, but doesn't call it an operator and doesn't list it in the table for operator precedence.
  • Many RISC architectures use three operands for common arithmetic operations: two to indicate input values and one to denote the result. Whether you'd call that an operator, and the result register an argument to that operator, is of course again a matter of perspective.

In general, many languages have a far less clear line distinguishing operators from functions on the one side or control constructs on the other side. In those cases it is often hard to decide whether some ternary construct is indeed an operator or not.