Replacing overloaded functions with closures.
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Jul 30 17:56:16 CEST 2007
king kikapu a écrit :
> i am trying, to no avail yet, to take a C#'s overloaded functions
> skeleton and rewrite it in Python by using closures.
> I read somewhere on the net (http://dirtsimple.org/2004/12/python-is-
> not-java.html) that in Python we can reduce code duplication for
> overloaded functions by using closures.
Then you should re-read more carefully this article. While closures are
effectively a great way to reduce code duplication, they are by no mean
presented as a way to replace function overloading - or at least not
directly. The idea presented here is to use closures to write
functions that will return "parameterized" functions, and (IMHE at
least) this is mostly useful in frameworks, ORMs and like.
 you may want to have a look at another work by the same author:
which introduces the RuleDispatch generic function package.
More information about the Python-list