5 ms·
Ternary operator is an expression, first implemented as COND in Lisp. In some cases it can be optimized to remove branching, especially when vectorized for SIM
by nivertech 4y ago
Ternary operator is an expression, first implemented as COND in Lisp.
In some cases it can be optimized to remove branching, especially when vectorized for SIMD/SIMT.
int a,b,c,d;
a = b ? c : d;
// optimized to something like this:
a = b*c + (1-b)*d
In some PLs even loop statements can produce values (CoffeeScript, Autocode), i.e. similar to list comprehensions, which are undoubtedly expressions.
I'm a kdb+/q developer, and most of the q code are expressions without conventional control flow operators (the only place they're used is outside of the main path: i.e. logging, testing, etc.).
IMO control flow (i.e. actual branching and looping) is just an implementation detail.