Modifying func_closure

Robert Brewer fumanchu at amor.org
Sun Jul 11 00:17:47 EDT 2004


I asked:
> Which immediately brings up the question: why not use a 
> class instead?

to which Jacek replied:
> a) The closure is faster, and my inner loops consist almost 
> entirely of them.
> 
> b) The closure is much clearer, shorter and more convenient. 
> I have so many of these things that using the class version
> would make the code a real mess.
> 
> c) The closure can be stuck on to a class, and works as a 
> method (bound & unbound and all that).
> 
> d) The outer function which creates the closure can be a method
> of a class.
> 
> Probably quite a few more ...

I have to wonder about 'b'; does anyone have an example where a closure
is clearer? Yes, this means you have to invent syntax to mutate the cell
variable if you want to discuss it. ;) Having perused previous
discussions, I think I'm favoring the 'lexical'/'outer' keyword idea;
seems we're just waiting for someone to write a PEP...


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list