Operator overloading

Hexamorph hexamorph at gmx.net
Fri Jan 25 15:52:24 EST 2008


MartinRinehart at gmail.com wrote:
> 
> Hexamorph wrote:
>> You mean you want the ability to change for example the + operator
>> for ints to something like calculating the cosine instead of doing
>> addition?
> 
> Sure. Cosines are a monadic operation and the monadic '+' is a NOP, so
> why shouldn't I define +45 to return cosine of 45, (presuming I needed
> lots of cosines). I'd even let you define your own operators. Lots of
> programmers really liked '++' and '--', for examples.

Well, OK, the cosine example was badly chosen (it would still be 
very wired in terms of common syntax and semantics), but I think you 
got my point. Changing internal behaviour mostly causes more trouble 
as it's worth.

In the end, you probably can access the parser to do this.




More information about the Python-list mailing list