Proposed PEP for a Conditional Expression

Gareth McCaughan Gareth.McCaughan at pobox.com
Thu Sep 13 17:25:14 EDT 2001


Terry Reedy wrote:

> > > I agree that the above is backwards.
> > > <cond> if <expr> else <expr>
> >
> > No! That sounds way too much like Forth!
> 
> It is exactly like C, whose ? : equivalent is the impetus for the
> proposed change.
> Of course, if you don't like the form of C's conditional expressions,
> you won't like its translation into Python.

It isn't exactly like C, because the C syntax doesn't
abuse the word "if". If you use words from a natural
language, it is best to use them in a way reasonably
compatible with that language. "<condition> if <expression> ..."
completely fails this test, and I too think it could only
appeal to someone who'd got used to it by programming in
Forth.

I don't read "cond ? a : b" in C as "cond if a else b".
Actually, I read it as "cond query a colon b", but that
just indicates that I have C's operators well internalized.
I suggest "cond chooses a or b", though that might be
misleading since "or" has other meanings. "Selects" might
be better than "chooses". Or, as I say, there's "query"
and "colon". :-)

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
.sig under construc



More information about the Python-list mailing list