Proposed PEP for a Conditional Expression

Jeremy Cromwell jtcromwell at yahoo.com
Wed Sep 12 17:36:01 EDT 2001


[excellent proto-PEP snipped]

I wonder if I could suggest other specifications.  

SPEC_6: Use condition as index of tuple.
    The currently legal syntax "x =
(false_val(),true_val())[cond]" would be used, but now
short-circuit.

    PRO - [pythonic] [no new keyword] [no new use of
'if']
    CON - [changes current functionality] 

The 'marker' for causing this to short-circuit is the
indexing of an anonymous, created on-the-fly tuple. 
This syntax would even allow "x = (choice_0(),
choice_1(), choice_2(), choice_3())[choice()]"

SPEC_7: Use condition as index "of" tuple.
    The syntax "x = cond of (false_val(),true_val())"
would be used.

    PRO - [semi-pythonic] [no new use of 'if']
    CON - [new keyword] 

This syntax would even allow "x = choice() of
(choice_0(), choice_1(), choice_2(), choice_3())"

<END OF SPECS>

While I am personally comfortable with the C syntax
(Sample: a = b ? c : d), I definitely agree that it is
not pythonic.  All of the other original SPECs are
"if" based, and to my mind the "if" is strongly
associated with doing DIFFERENT THINGS, while what we
want is different values (see ARG_24).

Note: The only reason I didn't put [hard to read] in
the CON section of SPEC_6 is that it's legal python
syntax.



__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com




More information about the Python-list mailing list