[Python-Dev] non-binary operators

Gary Herron gherron@islandtraining.com
Fri, 14 Feb 2003 10:39:52 -0800


On Friday 14 February 2003 09:54 am, Gerald S. Williams wrote:
> I'm *not* discussing PEP 308, since that's supposed to
> be happening on c.l.py. The operator names have been
> changed to protect the innocent. :-)

Oops.  The original post was to both lists (which seems excessive),
and then so was my response.

> Gary Herron wrote:
> > The above defines two binary operators "[POINTED]" and
> > "[STICK]" and a ternary operator "[POINTED]...[STICK]".
>
> [...]
>
> > can the action of the ternary operator be defined in
> > terms of the actions of the two binary operators?
>
> [...]
>
> > The answer is *NO*, all three expressions evaluate to
> > different results.
>
> Why is that any different from the following set, which
> are already three different expressions in Python?
>
>   ( bunch_of_grapes <   banana ) < pointed_stick
>     bunch_of_grapes < ( banana   < pointed_stick )
>     bunch_of_grapes <   banana   < pointed_stick

Good point.  I've never actually used (a<b<c), but I'm pleasently
surprised when reminded of it's existence.  There is however a
difference. A whole string of '<' operators (or even of string of
mixed '<' and '>' operators) can be understood by considering each
operation in isolation as a binary operation.  Not so with the "then"
and "else" operands.  

The easiest description of a string of "then" operators is that it
selects and returns the first "false" expression in the lists, and a
string of "else" operators selects and returns the first "true"
expresson, and both short-circuit the remaining operands.  The ternary
operator is not easily explained by some combination of the individual
binary operands from which it is composed.

Gary Herron