Ternary Operator and lazy evaluation -


is ternary operator example of lazy evaluation? if assume code snippet like: variable = condition ? function1(param) : function2(param); can example of lazy evaluation?

in languages - yes, evaluated lazily. not situation. wikipedia:

note languages may evaluate 'both' true- , false-expressions, though 1 or other assigned variable. means if true- or false-expression contain function call, function may called , executed (causing related side-effects due function's execution), regardless of whether or not result used.

for example, in delphi not lazily evaluated:

unlike true ternary operator however, both of results evaluated prior performing comparison. example, if 1 of results call function inserts row database table, function called whether or not condition return specific result met.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -