[Python-Dev] Re: PEP 285 (Adding a bool type) extending it further

Marcelo Matus mmatus@dinha.acms.arizona.edu
Thu, 03 Oct 2002 18:11:26 -0700


Yes, I can use the &,|,~ operators,  and that is what I am doing right now.

But your question also apply to the boolean type:

   can't you just use an integer type and leave it like that?


So, my suggestion was originated because if  there are users
which consider relevant to have a boolean type,
there will be situations when you will want to overwrite the specific
'boolean operators' too.

Maybe the overwrite of the 'and' and 'or' is not the solution, maybe is 
better
to add the && and || operators directly, like there is the pair / and //,
so 'and' and 'or' will be always the old and untouched version, with the 
shortcut properties,
and && and || could be the one you can overwrite, but they will not warranty
the shortcutting.

I guess that could be a happy solution for all, then

   a and b

is the old and traditional version, and

    a && b

could means something like:

    if a.bl_and exist:
      return a.bl_and(b)
   else if b.bl_rand exist:
      return b.bl_rand(a)
   else
      return a and b


Anyway, if python allow you to do all this beatifull  things overwriting 
 operators
for all the other types, and don't see anything special about the 
boolean type
that forbid you to want to overwrite and extend its operators.

Also note that the 'and' and 'or' operation have an specific meaning in the
mathematical abstract sense, like '&' and '|', and the shortcut property
doesn't have anynothing to do with it. In the computational implementation
of them the shortcut property is usefull, because usually you apply 
these operators
to entities which are not boolean objects and you extend their meaning.

But like the operators '&' and '|' don't require the shorcut porperty,
boolean types and boolean algebra don't require it either. If it is 
there, good, if not,
good also.

So, after writting this email, I would like to change the proposed 
extension to the
inclusion of the "pure boolean" operator &&, || and !, which can be 
overwritten
but in any way they warranty the shortcut property, like the bitwise 
cousins !,&,~,
and leave the 'and', 'or' and 'not' operations untouched with their 
"extended
computational meanings".


Marcelo


Jeremy Hylton wrote:

>Can't you just use & and | and leave it at that?
>
>Jeremy
>
>  
>