Re: Want to Use filter() with multi-variable function

Richard Henderson (richard@viz.tamu.edu)
29 Jul 1994 05:11:53 GMT

In article <317hu6$1cr@news.delphi.com>,
DAVEGOTTNER@DELPHI.COM <davegott@news.delphi.com> wrote:
> newlist = filter(lambda x, l=<expr1>, h=<expr2>: l <= x < h, oldlist)
>
>(This was the primary motivation for default arguments: to pass context
>for lambda)
>

Lambda in python has always confused me. Why is it not the case that in

def foo(low, high):
return lambda x: low <= x < high

low and high are not bound at the creation of the lambda? And another
thing: is it because of parsing problems that lambda is restricted to
a single expresion? In any case, because it is restricted, and
assignment is not something that can happen in an expression, the effect
of lisp-ish lambdas can be obtained by binding variables from the
local dictionary at the time the lambda is created.

r~
--------
richard@viz.tamu.edu