[Python-Dev] Re: ternary operators (fwd)

Tim Peters tim_one@email.msn.com
Tue, 1 Feb 2000 03:15:08 -0500


[Greg Wilson, quoting Philip Wadler]
> Tony Hoare had a nice ternary `if'.  He writes
>
> 	if c then d else e
>
> as
>
> 	d <c> e

Noting that he first wrote "if c then d else e" so it would be *clear* what
the heck he was talking about.  So that's exactly the point at which Python
should stop.  After that, it's no longer clear, just formally elegant.  I
love Haskell too (and thank Philip for that), but it ain't Python.

> This satisfies an associative law:
>
> 	d <c> (e <c> f)  =  d <c> f  =  (d <c> e) <c> f

Nobody writes nested ?: using the same condition twice; it's more
interesting as an endcase absorption law.  Does

   x <c1> (y <c2> z) = (x <c1> y) <c2> z

?  Nope (e.g., suppose c1 is true and c2 is false).