[Python-Dev] Boolean transition (original) (raw)

Samuele Pedroni pedroni@inf.ethz.ch
Sun, 10 Mar 2002 21:16:30 +0100


[Tim]

I liked the APL approach best, simply because it was most useful. Perhaps that's because my non-programming background is in discrete mathematics, where identifying 0/1 with false/true is of great practical value. For example, see "Concrete Mathematics" (Knuth, Graham and Patashnik), where treating a true/false result as 1/0 is so common it's indicated merely by surrounding a predicate expression with plain square brackets. This was a notational advance over the non-programming state of the art (most texts before CM, including Knuth's TAoCP, use a clumsy Kronecker delta notation). The programming state of the art would be advanced a little by Guido's PEP, in my view of the world.

I agree with Tim, additivity for booleans means that you can use predicates also as the indicator function of their corresponding sets:

def count_visible(win_list): c = 0 for win in win_list: c+=win.visible return c

Personally I find that very readable.

I can find also a senbible meaning for other mixed int/boolean arithmetic operations.

I can find also meaningless combinations but concretely what kind of errors would the separation avoid?

regards.