PEP308: Proposing function-call syntax
Anders J. Munch
andersjm at dancontrol.dk
Mon Feb 10 04:44:41 EST 2003
Yet-another PEP 308 proposal:
ifelse(condition, iftrue, iffalse)
That is, use plain old function call notation, but with 'ifelse' being
a keyword recognised by the interpreter, so that arguments are only
evaluated as necessary.
Example:
messsage = "Access " + ifelse(key=correct_key, "granted", "denied")
Pro:
Syntax is straightforward yet terse.
Order of evaluation left-to-right.
There's no confusing it with a statement.
'ifelse' is easy for newbies to search for in documentation.
Con:
Looks like a function call but isn't. People might expect arguments
to be fully evaluated.
Adds new keyword.
A possible variation: Call it 'cond' instead and allow for multiple
conditions.
cond(cond1, expr1, ..., condN, exprN, exprOtherwise)
- Anders
More information about the Python-list
mailing list