PEP 308: Alternative conditional operator forms
Mon Feb 10 02:27:15 CET 2003
Erik Max Francis <max at alcyone.com> writes:
> > cond(C, :x, :y) and some variants on this which I don't remember
> > exactly
> The cond(C, :x, :y) was just a builtin function cond using a new
> introduced syntax for "thunks" (zero-argument lambdas; :x would be short
> for lambda: x), so I don't think that really qualifies as a conditional
> operator a la PEP 308; it's a short-hand for lambdas and a function
> which uses them in a certain way, rather than a conditional operator
> (the conditional operator suggested above would be just one application
> of it).
I'd include it on the alternatives list anyway, along with macro
schemes, and anything else that accomplishes the functionality.
PEP 308 is motivated by the frequently asked question of "how do I do
something like ?:" and the recognition that the answers that result
are unsatisfactory to a lot of us. If there were a built-in
conditional function like the above, I think I would find that answer
satisfactory, especially if I thought the implementation wasn't
penalizing me too much for using it.
So I think a reasonable criterion for including something on your
alternatives list is: include it if you think it would make a
satisfactory answer to "how do I... ".
More information about the Python-list