(PEP-308) Python's Conditional Selection Operators

Terry Reedy tjreedy at udel.edu
Mon Feb 17 21:02:39 EST 2003


Stephen Horne writes

> Just how much time was Terry supposed to spend carefully excising
> every possible risk of people reading in judgement from what he
said?

Who knows.  I do know that I spend several hours of research and
writing.  To justify calling and/or  'conditional selection
operators', I defined 'conditional' and 'selection operator'.   I
compared them to the logic versions which they generalize and too
which they reduce in certain situations.  I discovered and included
two new-to-me and, I suspect, to-the-list facts.  The and/or idiom has
a dual or/and version, with a different failure case.  The two idioms
can be combined, in either order, to produce more complicated forms
that work 'correctly'.  (I had initially thought this to be
impossible.)

I spent some time trying to be terse without being cryptic and removed
some 'aside' comments.  In an attempt to keep attention on the main
points, I removed some expressions of opinion and anything that I
thought would be distractingly controversial.  I seem to have failed
in the very first sentence.  Writing introductions is hard, at least
for me.


I wrote:
> >  I know that in C (and I presume C++) and/or are extended
conditional
> >  logic operators,

and Gareth McCaughan replied:

> Actually, in C and C++ the <&&> and <||> operators (the nearest
> equivalent to Python's <and> and <or>) are purely boolean.

Actually, by the definitions of 'extended' [domain] and 'conditional'
[execution] that I gave in my essay, my sentence above is correct.  To
me, 'purely boolean' is a synonym for 'strict logic', which I defined
as mapping bool x bool => bool.  However, C && and || map all scalers,
including pointers and floats, and not just boolean values, to its
boolean int values.  If 'purely' includes this domain extension, then
the contrast implied by 'actually' seems non-existent.  So this
strikes me as another distractive quibble.  (But read on, Gareth)

Gareth also wrote:
> Here's an example of how you could have worded what you said
> so as not to confuse  useless quibblers like me.
>
>     Python's "and" and "or" operators differ from those that may
>     be familiar from mathematics, logic or theoretical computer
>     science, or even from some other languages such as C and C++.
>     In those domains, "and" and "or" are purely logical operations;
>    ... [etc]

I agree that this or something like it would have been a better way to
start.  I wish I had been able to get this suggestion *before*
posting.  I have saved it and, as promised, will use it to revise
before re-releasing the essay or some new version.

Terry J. Reedy






More information about the Python-list mailing list