Op 2005-01-12, It's me schreef <[EMAIL PROTECTED]>: > > "Robert Kern" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> >> That's *it*. > > So, how would you overload an operator to do: > > With native complex support: > > def twice(a): > return 2*a > > print twice(3+4j), twice(2), twice("abc") > > Let's presume for a moment that complex is *not* a native data type in > Python. How would we implement the above - cleanly?
I suppose in the same way as (graphic) points and vectors can be implemented cleanly. A few years back I had written a Vector class in python, just to get an understanding of how things worked. It worked without a problem with your twice function. >>> Vec(1.0,2.0) Vector[1.0, 2.0] >>> def twice(a): ... return 2 * a ... >>> twice(Vec(1.0,2.0)) Vector[2.0, 4.0] >>> I suppose what can be done with a vector class could have been done with a complex class should complex numbers not have been native to python. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list