[Python-ideas] Revisiting dedicated overloadable boolean operators

Dan Sommers dan at tombstonezero.net
Sat Aug 4 10:04:01 EDT 2018


On Sat, 04 Aug 2018 23:13:34 +1000, Steven D'Aprano wrote:

> There are certainly advantages to using binary operators over named
> functions, and a shortage of good, ASCII punctuation suitable for new
> operators.

Hold that thoght.

Then again, why is it 2018 (or 5778?) and we're still stuck with ASCII?
Doesn't Unicode define a metric boatload of mathematical symbols?  If
Pythong allows Unicode names,¹ why not Unicode operators?

¹ No, I'm not going to call them variables.  :-)

> I don't think much of your names bOR etc.
> 
> I think that before adding more ad hoc binary operators, we ought to
> consider the possibility of custom operators [...]
> 
>     a ~foo b

Great.  Yet another way to spell a.foo(b).  Or foo(a, b).  :-/

> Although possibly we might choose another pseudo-namespace, to avoid
> custom operators clashing with dunders. Trunders perhaps? (Triple
> underscores?)
> 
> Under this scheme, your operators would become:
> 
>     ~or
>     ~and
>     ~xor
> 
> and call trunders ___or___ etc.

And now mental gymnastics to jump from ~foo to ___foo___ or ___rfoo___.

If it's too hard to tell = from == (see endless threads on this mailing
list for proof), then it's also too hard to tell __xor__ from ___xor___.

If I want to say

    a ~foo b

then why can't I also say

    class A:
        def ~foo(self, b):
            pass # do something more useful here



More information about the Python-ideas mailing list