I sing the praises of lambda, my friend and savior!

Jeff Shannon jeff at ccvcorp.com
Wed Oct 13 15:04:00 EDT 2004


Cliff Wells wrote:

>Hi Jeff,
>
>Jumping in way late in this thread, I'll toss in my pennies and say I
>still use lambda fairly regularly in one place, and it just happens to
>be the very place where I learned of lambda in the first place: event
>handlers for GUI programming.  I first learned the technique in Tkinter
>circa 1.5.2 and still use it in wxPython.  It isn't strictly necessary,
>but given the already cluttered nature of GUI programming, I'm pretty
>reluctant to toss in four or five more names every time I want a
>complicated event handler to get called with slightly different
>arguments. Basically I use it as a poor-man's curry (if I understand
>currying correctly, I've only seen conversations about it on this list
>and that's the impression I was left with: that it's a way of providing
>variations in the default arguments to a function).
>  
>

That's my understanding of currying, as well, and I too know it only 
from discussion on this list. ;)  But I recall that Alex Martelli, some 
time ago, provided a wonderful explanation of currying and a recipe or 
two for how it can be generically accomplished.  (Before that 
explanation, I'd had no idea where the term came from and had been 
trying to work out how it coud be etymologically related to, say, 
currying horses... ;) )  I believe that his solution involved callable 
class instances that store the function to be called and the known 
parameters as attributes.  That *was* quite a while ago (possibly even 
pre-2.2), though, so I don't know whether it'd still be the most 
effective recipe... and my memory about it is a bit flakey.

>As I know you're a wxPython user as well, I'd be curious to know how you
>approach this particular problem.
>  
>

To be honest, I've rarely felt the need to do much currying in my 
wxPython (or other) applications.  Maybe it's a design thing -- I tend 
to make every non-trivial component I use be a custom class/subclass, 
even if I'm only going to use it in one place, and it seems appropriate 
to have methods on that class which encapsulate its desired  behavior to 
the point where currying isn't necessary.  The closest I've come to 
needing currying is handled neatly by wxCallAfter(), which takes a 
function and a list of arguments to pass to that function.  Then again, 
almost everything I've done so far has been fairly simple (as in low 
complexity, not necessarily easy...), so it's possible that I'm the odd 
one here...

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list