Is ternary operator meant to use lazy evaluation? #797
Answered by antonmedv
mdmcconnell asked this question in Q&A
-
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.
Answered by antonmedv May 30, 2025
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.
0 replies
Answer selected by antonmedv
-
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.
3 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.