For review: PEP 308 - If-then-else expression
Chris Liechti
cliechti at gmx.net
Mon Feb 10 18:49:11 EST 2003
> [Michael Hudson]
>> This has been an eye-opener for me: people really do write
>> x and y or b
that does not surprise me, i'm using it sometimes ;-)
Tim Peters <tim.one at comcast.net> wrote in
news:mailman.1044908798.21634.python-list at python.org:
> Offhand, at first glance I don't find
>
> y if x else b
>
> any more sensible than
>
> x and y or b
i _was_ for a ternary op, because such a thing would show the intent of a
programmer more precise than "c and t or f". of course i can live with the
later and i have to use it if i want to be compatible with 2.2 (the python
in a tie version).
on the other hand, what i see in this discussions is that i rather live
forever with "and or" than having some of the ugly proposals in the
language ;-) (Guidos is not bad, but "if t if cond else f" doesn't look
exactly good and such things will come up even if and/or would be better
placed here)
how about a ifte(cond, true_v, false_v) function in a "functional" module.
that could also take a curry(f, *args, **kwargs) function and some other
functional style helpers.
and for those realy rare cases where lazy eval matters, there is the "and
or" solution or the form as a statement. especialy if an expression has so
drastical consequences that it must no be evalueted (if the other is
taken), it should go in a ordinary "if", that is much clearer and you have
space to put comments on why it is so important to take care.
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list