True/False story... (PEP 285)

Petr Prikryl Answer.via.news.please.prikryl at skil.nospam.cz
Thu Apr 11 03:46:00 EDT 2002


Boris wrote...
>
> Alex Martelli wrote:
> >
> > there IS a natural mapping of booleans onto a subset
> > of integers, just as there is a natural mapping of
> > integers onto a subset of reals (or rationals, etc).

But does it help somehow?

I do not know from what thread the Alex's notice was
cut, and what was the point.  I agree that there is
natural mapping between booleans and integers.  There
even is natural mapping between natural numbers and any
data that is used by computers (the RAM can be
viewed as a single, very big natural number, the same
way the disk space can be interpretes, but it does not
makes the things easier).

The same way, you probably would not be happy if someone
decided to remove strings and to replace them by
sequences of integers.

To summarize, bool type is related to a different
abstraction than the integer type.  Bool is the most
natural type (conceptually) for capturing
conditional-expression results.

Moreover, strict boolean does not require ordering of
False, True.  In other words, the only comparison
operators are '==' and '!='.  Then, the mapping of
boolean into integer adds some implementation details
that should not be abused if one want to preserve the
original meaning of the booleans -- this is the problem
that was unfortunately introduced into C/C++/Python
implementation of conditional expressions at the
beginning.

Boris...
>
> Could be argued that there is no single natural mapping,
> for an alternate to the current one we could have
>
> True     == 1
> False    == -1
> not x    == -x
> x and y  == min(x,y)
> x or y   == max(x,y)
> x xor y  == -x*y
>
> A nice feature of that one (to my aesthetics), is that
>
> 1j == sqrt(False)

This alternate mapping breaks everything that exists now
and does not introduce anything better than the existing
state.

Andrew wrote...
>
> Quoting Hilbert,
>
>    "It must always be possible to substitute 'table',
>     chair' and 'beer mug' for 'point', line' and 'plane'
>     in a system of geometrical axioms."

;-)

> I personally started with a BASIC which had 0 for false
> and -1 (all bits on) for true.

In comparison with Python (C/C++), this is only a minor
*flavour* of the same.  Well, I were used to 0 and !=0
in C/C++, but I prefer to think in booleans.  And I also
always prefer new bool in C++ since it was introduced
into the language.

Petr

P.S. The HTML version of the original
     "True/False story... (PEP 285)" is temporatily available
     at http://www.skil.cz/test/TrueFalseStory.html
--
Petr Prikryl (prikrylp at skil dot cz)





More information about the Python-list mailing list