[Python-ideas] logics (was:thoughts on generator.throw())

R. David Murray rdmurray at bitdance.com
Thu Mar 19 01:37:55 CET 2009


spir <denis.spir at free.fr> wrote:
> Le Wed, 18 Mar 2009 13:10:52 -0400,
> I would go much farther that python about logical types and operators.
> 
> Lazy evaluation is ok, because the alternative is not simpler:
>    if n != 0 and 1/n > threshold: 
> 
> But I'm not happy at all with the following:
>    >>> (3==3) + 1
>    2
>    >>> 1 or True
>    1
> 
> I think logical operators (and or not) should accept only logical value. And
> logical values should not operate with numbers. 

I might be argued into agreeing with you about the first case, but
it might be a logical consequence of the implementation of the second
case.  Or it might be an historical accident, since True used to be 1.
(But the statement still gives that result in Python3, so unless it was
just overlooked in the cleanup, someone must think it is a good idea.)

But I would very definitely not want to give up the second example.
Having the shortcut logical operators return the actual value that
was last evaluated is just too darn useful :)

--
R. David Murray           http://www.bitdance.com




More information about the Python-ideas mailing list