Is ternary operator meant to use lazy evaluation? #797
-
I had some expressions of the form "false ? do_something() : do_otherthing()", and it seems as though do_something() was always called. Before I spend much time working up a test - is ternary operator even meant to use lazy evaluation? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Yes! Ternary operator designed to be short circuiting. If you need to run both expressions, assign the to variables. And use ternary operator on them. |
Beta Was this translation helpful? Give feedback.
-
Strange - The behaviour I observed indicates the opposite. Maybe it is application-specific; must run a few tests. I'll revert if I find anything interesting. |
Beta Was this translation helpful? Give feedback.
Yes! Ternary operator designed to be short circuiting.
If you need to run both expressions, assign the to variables. And use ternary operator on them.