Lambda as declarative idiom (was RE: what is lambda used for in real code?)

Steven Bethard steven.bethard at gmail.com
Tue Jan 4 09:55:05 EST 2005


Bengt Richter wrote:
> On Mon, 03 Jan 2005 18:54:06 GMT, Steven Bethard <steven.bethard at gmail.com> wrote:
> 
> 
>>Roman Suzi wrote:
>>
>>>I wish lambdas will not be deprecated in Python but the key to that is
>>>dropping the keyword (lambda). If anybody could think of a better syntax for
>>>lambdas _with_ arguments, we could develop PEP 312 further.
>>
>>Some suggestions from recent lambda threads (I only considered the ones 
>>that keep lambda as an expression):
>>
> 
> Just for reference, am I correct in assuming these are the equivalent
> uses of lambda?:
> 
>  lambda a, b, c:f(a) + o(b) - o(c)
>  lambda x: x * x
>  lambda : x
>  lambda *a, **k: x.bar(*a, **k)
>  (lambda : x(*a, **k)) for x, a, k in funcs_and_args_list)

Yeah, I believe that was the intention, though I stole the examples from 
[1].

> That last seems like it might need the default-arg-value hack: i.e.,
>  (lambda x=x, a=a, k=k: x(*a, **k)) for x, a, k in funcs_and_args_list)

Good point.

Steve



More information about the Python-list mailing list