Operator overloading

MRAB google at mrabarnett.plus.com
Sat Jan 26 19:57:51 EST 2008


On Jan 25, 8:52 pm, Hexamorph <hexamo... at gmx.net> wrote:
> MartinRineh... 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.

You'd probably want the change to be limited to a certain scope so
that, for example, it doesn't affect imported modules.



More information about the Python-list mailing list