473,574 Members | 2,660 Online

# bool behavior in Python 3000?

Is there any discussion of having real booleans
in Python 3000? Say something along the line
of the numpy implementation for arrays of type 'bool'?

Hoping the bool type will be fixed will be fixed,
Alan Isaac
Jul 10 '07 #1
57 3354
Alan Isaac wrote:
Is there any discussion of having real booleans
in Python 3000?
I'm not sure how the bools we have now are not "real."
Say something along the line of the numpy implementation for arrays
of type 'bool'?

What aspect of this do you want? A bool typecode for the stdlib array
module?

I can guess a number of things that you might mean, but it would be best
if you explained with an example of what current behavior is and what
you would like it to be.
--
Michael Hoffman
Jul 10 '07 #2
Alan Isaac wrote:
Is there any discussion of having real booleans
in Python 3000?
The last I have seen is

http://mail.python.org/pipermail/pyt...ry/005284.html
Hoping the bool type will be fixed will be fixed,
Do you care to explain what is broken?

Peter

Jul 10 '07 #3
Peter Otten wrote:
The last I have seen is
http://mail.python.org/pipermail/pyt...ry/005284.html
OK. Thanks.

Do you care to explain what is broken?
I suppose one either finds coercion of arithmetic operations to int
to be odd/broken or does not. But that's all I meant.

My preference would be for the arithmetic operations *,+,-
to be given the standard interpretation for a two element
boolean algebra:
http://en.wikipedia.org/wiki/Two-ele...oolean_algebra

In contrast with the link above,
it does not bother me that arithmetic with ints and bools
produces ints.

Cheers,
Alan Isaac
Jul 10 '07 #4
Alan G Isaac wrote:
Do you care to explain what is broken?

I suppose one either finds coercion of arithmetic operations to int
to be odd/broken or does not. But that's all I meant.

My preference would be for the arithmetic operations *,+,-
to be given the standard interpretation for a two element
boolean algebra:
http://en.wikipedia.org/wiki/Two-ele...oolean_algebra
If I understand this right, the biggest difference from the current
implementation would be that::

True + True == True

True + True == 2

What's the advantage of that? Could you give some use cases where that
would be more useful than the current behavior?

It's much easier to explain to newcomers that *, + and - work on True
and False as if they were 1 and 0 than it is to introduce them to a two
element boolean algebra. So making this kind of change needs a pretty
strong motivation from real-world code.

Steve
Jul 10 '07 #5
> Do you care to explain what is broken?
> My preference would be for the arithmetic operations *,+,-
to be given the standard interpretation for a two element
boolean algebra:
http://en.wikipedia.org/wiki/Two-ele...oolean_algebra

If I understand this right, the biggest difference from the current
implementation would be that::

True + True == True

True + True == 2

What's the advantage of that? Could you give some use cases where that
would be more useful than the current behavior?
I prefer the use of 'and' and 'or', and they feel more pythonic than & and
+

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 10 '07 #6
Alan Isaac wrote:
Hoping the bool type will be fixed will be fixed,
Is there any type named "bool" in standard Python?

Regards,
Björn

--
BOFH excuse #207:

We are currently trying a new concept of using a live mouse.
Unfortunately, one has yet to survive being hooked up to the
computer.....pl ease bear with us.

Jul 10 '07 #7
Alan G Isaac wrote:
My preference would be for the arithmetic operations *,+,-
to be given the standard interpretation for a two element
boolean algebra:
http://en.wikipedia.org/wiki/Two-ele...oolean_algebra
>>[bool(True+True) , bool(True+False )]
[True, True]

Works for me, or did I misunderstand you?

If you don't want explicitly to write bool, you could define your
own True and False classes.

Regards,
Björn

--
BOFH excuse #184:

loop found in loop in redundant loopback

Jul 10 '07 #8

"Alan Isaac" <ai****@america n.eduwrote in message
news:z0Oki.1782 \$YH3.1751@trndd c08...
| Is there any discussion of having real booleans
| in Python 3000? Say something along the line
| of the numpy implementation for arrays of type 'bool'?

As far as I know, there is no such discussion among the developers.
Clp is always a different matter ;-)

Jul 10 '07 #9
Michael Hoffman <ca*******@mh39 1.invalidwrites :
Alan Isaac wrote:
Is there any discussion of having real booleans
in Python 3000?

I'm not sure how the bools we have now are not "real."
I'm guessing that Alan is referring (at least in part) to this behaviour:

Python 2.4.4 (#2, Apr 5 2007, 20:11:18)
[...]
>>True == 1
True
>>False == 0
True

Whereas a real bool type would have discrete values for True and False
that would not be equal to any other.

--
\ "I guess we were all guilty, in a way. We all shot him, we all |
`\ skinned him, and we all got a complimentary bumper sticker that |
_o__) said, 'I helped skin Bob.'" -- Jack Handey |
Ben Finney
Jul 10 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.