Re:Statements vs. Expressions
by nivertech on Thursday July 14, 2022 @09:52AM
(#32096107)
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.
In some cases it can be optimized to remove branching, especially when vectorized for SIMD/SIMT.
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.