PEP 308: Alternative conditional operator forms
Bengt Richter
bokr at oz.net
Mon Feb 10 23:21:41 EST 2003
On Mon, 10 Feb 2003 09:41:46 +0200, Christos "TZOTZIOY" Georgiou <DLNXPEGFQVEB at spammotel.com> wrote:
>On Sun, 09 Feb 2003 16:22:38 -0800, rumours say that Erik Max Francis
><max at alcyone.com> might have written:
>
>>Here is the list I have so far (C represents the conditional expression,
>>x the if-true expression, y the if-false one):
>>
>>x if C else y # initial proposition in PEP
>>C ? x ! y # mentioned in PEP
>>(if C then x else y) # mentioned in PEP
>>x when C else y
>>(if C: x else: y)
>>C ? x else y
>>C -> x else y
>>C -> (x, y)
>>
>>What else should be on this list? (You can reply by email if you wish.)
>
>C then x else y
C -> x -> y
This is a concise ternary based on a larger concept (from lisp via Paul Moore with my twist):
the concept was [C1 -> v1; C2 -> v2; C3 -> v3; True -> vDefault] I.e., evaluate Ci's until
you find one that's true, then evaluate its companion v. My twist is to drop the brackets
and supstitute '><' instead of ';'. Thus
C1 -> v1 >< C2 -> v2 >< C3 -> v3 >< True -> vDefault
with a single condition, you have
C1 -> v1 >< True -> vDefault
and by making the final condition introducer '><' and its condition (True) optional, you get
C1 -> v1 -> vDefault
which expresses the ternary nicely without keywords.
Regards,
Bengt Richter
More information about the Python-list
mailing list