[Python-ideas] [Python-ideos] Dedicated overloadable boolean operators

Ryan Gonzalez rymg19 at gmail.com
Tue Nov 24 18:00:34 EST 2015



On November 24, 2015 4:45:45 PM CST, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>MRAB wrote:
>
>> That still doesn't deal with the issue of what should happen if the
>> order is reversed, e.g. "numpy_array and simple_bool" vs "simple_bool
>> and numpy_array", where "numpy_array" has the non-shortcircuiting
>> behaviour but "simple_bool" hasn't.
>
>That's true.
>
>I guess the only solution that really works properly is
>to have a second set of operators, or some way of flagging
>that you're using non-short-circuiting semantics.
>
>There's one language I've seen -- I think it was Eiffel,
>or maybe Ada -- that had two sets of boolean operators.
>But it was kind of the other way around: 'and' and 'or'
>were non-short-circuiting, and to get short-circuiting
>you had to say 'and then' or 'or else'.

That was a lot of languages:
- Ada: and then, or else
- Algol: ANDTHEN, ORELSE
- Erlang: andalso, orelse
- Extended Pascal: and_then, or_else
- GNU Pascal: and then, or else
- Oz: andthen, orelse
- Standard ML: andalso, orelse
- Visual Basic: AndAlso, OrElse

Interestingly, Visual Basic allows you to overload non-short-circuiting And. To overload AndAlso, you need to overload And and IsFalse. It seems that AndAlso was roughly equivalent to And + IsFalse:

A AndAlso B

=

If Not (IsFalse A) Then A And B Else A Endif
-- 
Sent from my Nexus 5 with K-9 Mail. Please excuse my brevity.


More information about the Python-ideas mailing list