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

Kiuhnm kiuhnm03.4t.yahoo.it
Fri Apr 20 14:21:02 EDT 2012


On 4/20/2012 19:49, Jussi Piitulainen wrote:
> 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.

It's clear that Python wasn't developed with DSLs in mind. That's not a 
bad thing. It's just the way it is.
Nice work with that '-=1>', by the way :)
Another option is to rely on ugly pseudo-operators:
   a .imp. b
   a .imp (b .imp. c)

Kiuhnm



More information about the Python-list mailing list