3 ms·
Ok, I've always wondered about that '?' operator. What's the point? It was said (at the time) that C-like syntax meant a program was a series of expression, no
by JoeAltmaier 14y ago
Ok, I've always wondered about that '?' operator. What's the point?
It was said (at the time) that C-like syntax meant a program was a series of expression, not statements. So something like
(void)1;
is valid syntax. Even compound expressions are valid:
a=5, b=6;
Where I feel abandoned (betrayed?) is this: why then aren't compound statements also expressions? E.g.
{
int x=Foo(50);
Bar(x);
}
The value returned could just be the value of the final executed expression (Bar yields a value). No need for 'return' at all.
And no need for '?'.
int x = { if (i > j) 5; else 6; }
- vorg 14y agoYou're right about statements being expressions and returning the last executed expression. In fact, since using Clojure I've gotten used to these, e.g. (-> (Foo 50) (Bar)) (def x (if (> i j) 5 6)) I do miss the static typing and more readable syntax, though, and have appreciated Haskell in this regard. Too bad things like powerful macros and convenient syntax don't seem to gel together well in the same language.