[Python-Dev] Rich comparison confusion

Tim Peters tim.one@home.com
Sun, 21 Jan 2001 20:23:27 -0500


[Michael Hudson]
> ...
> if you meant min(a,b), then I then think the programmer who
> thinks "min(a,b)" is spelt "a<b" has problems we can't be expected to
> deal with (if min has a symbol it's /\, but never mind that).

Curiously, in the Icon language, if a is less than b then

   a < b

returns b while

   b > a

returns a.

In this way they get the same effect as Python's chained comparisons

   a < b < c < d

via purely binary operators (if a is *not* less than b, a < b in Icon
"fails", which is a silent event that causes the expression's context to
backtrack -- but we won't go into that here <wink>).

Anyway, that accounts for this curious Icon idiom:

   a <:= b

which is short for

   a := a < b

and binds a to max(a, b) (if a is smaller, a < b returns b and the
assignment proceeds; but if a is not smaller, a < b fails and that
propagates into its context, which here has no other possibilities to
backtrack into, so the stmt just ends leaving a alone).

"<"-and-">"-are-just-bags-of-pixels-ly y'rs  - tim