A library approach to the ternary operator
Lenard Lindstrom
nada at nowhere.xxx
Fri Mar 21 16:24:58 EST 2003
"David Abrahams" <dave at boost-consulting.com> wrote in message
news:ur890wwwv.fsf at boost-consulting.com...
>...
> from ternary import *
> select(condition and [true_result] or [false_result])
>...
My choice would be:
# ternary module
def select(test, fn_iftrue, fn_iffalse):
if test:
return fn_iftrue()
return fn_iffalse()
then:
from ternary import *
x = select(condition, lambda:true_result, lambda:false_result)
Maybe its my lisp background, but using unevaluated expressions as function
arguments seems a natural approach to implementing short-circuited behavior.
Lenard Lindstrom
"%s@%s.%s" % ("len-l.", "telus", "net")
More information about the Python-list
mailing list