Why functional Python matters

Will Stuyvesant hwlgw at hotmail.com
Thu Apr 24 05:18:03 EDT 2003


[Tim Peters]
> ...
>     class make_adder:
>         def __init__(self, n):
>             self.n = n
> 
>         def __call__(self, i):
>             return self.n+i
> 
> It often proves much better to carry state around in explicit objects
> instead of in hard to introspect, or to modify (unless you planned for that
> from the start), anonymous closures.  
> ...
> when-you-don't-have-a-hammer-only-nails-look-like-nails-ly y'rs  - tim

Another great posting Tim!  Who much time do you take to write
something like that?
Indeed, using a class it would be possible to *extend* a hammer, for
example such that it counts how much hits it did.  With *pure*
closures this would be a pain.

closure-classes-for-hammers-that-count-ly y'rs




More information about the Python-list mailing list