(PEP-308) Python's Conditional Selection Operators

Gareth McCaughan Gareth.McCaughan at pobox.com
Tue Feb 18 18:55:03 EST 2003


Terry Reedy wrote:

>  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 thought that bit was very neat, by the way. Completely
hopeless in practice, of course, but you already know that. :-)

>  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)

Mea culpa; I hadn't realised that was what you meant by "extended"
there. I thought you were referring to the non-bool return thing.
Sorry about that. (Should I have understood from the fact that you
wrote "conditional logic" rather than "conditional selection"? Oh
well.)

>  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.

Cool. (In case it needs to be said for stupid copyright reasons:
feel free to steal all or any or none of it for whatever purposes
you please.)

By the way, Stephen evidently considers what I've written in this
thread to be an attack on you. Please accept my assurance that nothing
I've written has been intended to be anything of the sort, and my
apologies if you've felt attacked.

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




More information about the Python-list mailing list