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

Piet van Oostrum piet at cs.uu.nl
Sun Feb 9 14:09:35 EST 2003


>>>>> Alex Martelli <aleax at aleax.it> (AM) wrote:

AM> Piet van Oostrum wrote:
AM>    ...
>> What about:
>> condition -> (true part, false part)
>> The (,) is not a tuple here but it belongs to the -> and the -> says to
>> select one of the expressions based on the condition and evaluate that;
>> kind of lazy indexing.
>> 
>> We could then also have one for ints rather than bools:
>> 
>> i -> [ v_0, v_1, v_2, ... ]
>> which would pick v_i and evaluate that.

AM> This is the first syntax I've seen proposed for this that I _like_.

AM> I particularly like the generalization to an int on the LHS of the
AM> new proposed -> operator.  However, I am slightly troubled by the
AM> subtly different syntax for the two-alternatives vs N-alternatives
AM> usages.  Whatever kind of parentheses are used, couldn't the
AM> number of alternatives listed inside the parentheses be the ones
AM> that control whether the LHS is taken as int or condition?  Or
AM> would that be unpythonic?  I don't feel very certain about this.

This would cause a subtle problem, which by the way is now also present if
someone confuses the parentheses:

If b is a variable that takes only 0 and 1 as values then

b -> (x, y) is the same as
b -> [y, x]

because with boolean conditionals people are used to have the true clause
first. And we shouldn't change that.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl




More information about the Python-list mailing list