Functions, Operators, and Overloading?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Jul 24 14:20:48 EDT 2006


Michael Yanowitz:

> Maybe I am missing something, but from what I've seen,
> it is not possible to overload functions in Python.

Maybe here you can find some ideas:
http://www.artima.com/forums/flat.jsp?forum=106&thread=101605
http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/
http://blog.ianbicking.org/more-on-multimethods.html


> (on the side, I have always wanted to define the
> ++ operator as +=1. Is that possible?)

That's not possible. Maybe you can create an inc() function, similar to
the Pascal one, that with a bit of stack-based magic may increment the
value its called on, but I think this is a bad idea. Leading/trailing
++/-- are quite bad for a language that tries to be clear and to avoid
programmer errors.

Bye,
bearophile




More information about the Python-list mailing list