For review: PEP 308 - If-then-else expression

Andrew Koenig ark at research.att.com
Sun Feb 9 21:29:13 EST 2003


holger> Maybe Roman Suzi (IIRC) has found one (short-circuiting)

holger>     cond -> (true_expr, false_expr)

holger> which i am currently thinking about.  

I'm not thrilled about this example because if you cover up the
"cond ->" part, you get what looks like a tuple, and tuples don't
short-circuit.

I'd be happy with

        true_expr if cond else false_expr

but must confess that I'm growing more in favor of

        if cond: true_expr else: false_expr

even though it looks like an if statement -- or perhaps *because*
it looks like an if statement.

I don't think there's any real ambiguity from the compiler's
viewpoint, because "if" denotes a statement only when it is the first
token of the statement and an expressin otherwise.

I also don't think that there's any real ambiguity from the
programmer's viewpoint, because the meaning is conceptually the
same for expressions as for statements.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark




More information about the Python-list mailing list