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

Dave Benjamin dave.benjamin at gmail.com
Mon Jan 3 11:16:01 EST 2005


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.

Well, my vote is still with Ruby-style codeblock syntax, but as a 
compromise, what about the following:

   fun(a, b): a + b

as a replacement for:

   lambda a, b: a + b

Advantages:
   - Doesn't use the l-word
   - Uses parentheses always
   - "fun" is shorter and self-describing
   - Makes Python code more "fun" ;)

Disadvantages:
   - Requires a new keyword, breaking backward compatibility
     (I'm assuming we're still talking about Py3k here)
   - (Still) doesn't interface statements with expressions

Dave



More information about the Python-list mailing list