Re: lambda construction
Wed, 15 Jun 1994 10:16:47 +0200

Tim has already given you a solution (which I was about to give as
well, quoting from my version of you-know-which-function :-), so I'll
just pick a nit:

> 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

Actually, ofunc is *never* bound inside that lambda! If you were to
call it inside wrap it would also fail. Python is not Lisp! It has
static scoping. As far as the code generator is concerned, ofunc
isn't a local variable (never assigned to) so it must be global -- and
global means in the module's scope, or possibly a built-in.

BTW I am thinking about optimizing the distinction between globals
and built-ins in the same manner as that between locals and globals --
scan the entire module for assignments, including global statements in
its functions and methods; anything that isn't obviously global must
be built-in. This may stop some code from working but that would've
been walking on thin ice anyway. It won't break lambda any more than
it's already broken. Given the relative frequency with which
built-ins like len, range and str are called this may be a worthwhile
optimization. It will also strengthen the notion that Python has
static scoping, and thus open the door for more stringent static
checking. (Well, at least set it slightly ajar...)

--Guido van Rossum, CWI, Amsterdam <>
URL: <>