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

Piet van Oostrum piet at cs.uu.nl
Sun Feb 9 16:30:09 CET 2003


>>>>> Erik Max Francis <max at alcyone.com> (EMF) wrote:

EMF> Michele Simionato wrote:
>> Interesting. I would accept this or the "when" proposal. But I am not
>> sure if other Pythonistas would like a new special symbol "->" only
>> used in the
>> ternary operator. Maybe you should think of other case of use for
>> "->".

EMF> Since the ? : form is declared unusable by fiat (and I must say I agree,
EMF> it overloads the use of the colon too much), it seems only reasonable
EMF> that the two intervening things in the ternary conditional operator be
EMF> keywords, and both be keywords.  Having one a symbol (whether already
EMF> used in the language or not) and the other a keyword (whether already
EMF> used or not) seems unclear.

It just dawned on me that the 'if' is not really necessary.
"->" would be a more pythonic operator than "?" I think, because it stands
out more. And indeed it looks a bit strange to have the other part as a
keyword.

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.
Also here the [ ] is not really a list notation but belongs to the ->.

The parentheses also prevent association ambiguity.
-- 
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