AW: Ternery operator
:: Uwe Schmitt writes:
:: > Normaly[sic] you should simulate "C ? T : F"
:: > either by
:: > [T,F][not C]
:: > or
:: > (C and [T] or [F])
:: > in the first case T and F are evaluated[sic] allways[sic],
:: > the latter solution does short circuit evaluation,
:: > which is according to the C/C++ semantics of the
:: > ternary operator.
:: NOT TRUE!
:: NEITHER of your options does short-circuit evaluation. That's
:: part of why many people (myself included) wanted to have a
:: conditional expression (more accurate term than "ternary operator").
The second one does short circuit evaluation, try the following:
print "T called"
print "F called"
res1 = (1 and [T()] or [F()])
res2 = (0 and [T()] or [F()])
|All times are GMT. The time now is 02:05 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.