can I overload operators like "=>", "->" or something like that?

Jussi Piitulainen jpiitula at ling.helsinki.fi
Fri Apr 20 13:49:28 EDT 2012


Kiuhnm writes:
> On 4/20/2012 17:50, Nobody wrote:
> > On Thu, 19 Apr 2012 12:28:50 -0700, dmitrey wrote:
> >
> >> can I somehow overload operators like "=>", "->" or something
> >> like that?  (I'm searching for appropriate overload for logical
> >> implication "if a then b")
> >
> > You cannot create new operators, but you can control how existing
> > operators work on types which you define.
> >
> > IOW, you can't define "->" or "=>", but you could define">=" or
> > ">>".
> 
> You can also "overload" '<-' ;)

Huh. If you're thinking what you just made me think, maybe x -=1> y
could be made to work. Think of --> but Python doesn't have -- ...

I forget whether it is just the Java people or also the Python group
who feel very strongly that the truth values should not really be
ordered and it is something like a bug in the language that they are.

Because <= already works as a material implication for the built-in
True and False to a certain extent: not for general truth values, and
x <= y <= z does not mean x <= (y <= z), and seen as an arrow the
symbol does feel backwards, and probably other such issues.



More information about the Python-list mailing list