lambda construction

Bill Janssen (janssen@parc.xerox.com)
Tue, 14 Jun 1994 20:43:32 PDT

I'd like to use lambda to write a wrapper function, but I can't figure
out quite how. The problem is to take a function 'ofunc' which accepts
some unknown number of arguments, and wrap it in another function
'wfunc', which takes the same number of arguments, but does something to
them, then calls 'ofunc' on them. I'd like to be able to say something
like:

def wrap (ofunc):
return lambda *args: (process_args(args), apply (ofunc, args))[1]

The problem is that once I've returned, "ofunc" isn't bound. So how to
write this? If I knew the number of arguments, I'd write

def wrap (ofunc):
return lambda a1, a2, f=ofunc: (process_args((a1, a2)), f(a1, a2))[1]

But I don't.

Bill