Replacing overloaded functions with closures.

king kikapu aboudouvas at panafonet.gr
Mon Jul 30 11:42:08 EDT 2007


> The closures discussed in the article are not a solution for
> function overloading. They are a solution for function
> composition.

Hmmm....

>
> Python generally has no need for function name overloading--if
> you really want it you must do it manually using runtime type
> checking.
>
> def func(obj):
>   if isinstance(obj, bool):
>     return not obj
>   elif isinstance(obj, int):
>     return obj * 2
>   elif isinstance(obj, basestring):
>     return obj + obj
>   else:
>     raise NotImplementedError('type %r not supported' % type(obj))

I have already come up with that solution but i was a little excited
from that article that i can do the same thing with closures...And get
rid of the isinstance commands.


> I'm not sure what the author was getting at, exactly.

May be that point confused me too!

Thanks Neil!




More information about the Python-list mailing list