Multi-line lambda proposal.

Kaz Kylheku kkylheku at
Tue May 9 19:14:12 CEST 2006

Kaz Kylheku wrote:
> But suppose that the expression and the multi-line lambda body are
> reordered? That is to say, the expression is written normally, and the
> mlambda expressions in it serve as /markers/ indicating that body
> material follows. This results in the most Python-like solution.

Unfortunately, while this idea has intuitive appeal, it leaves some
problems to solve; namely, lambdas that occur in expressions embedded
within statement syntax which has body material of its own. For

  # lambda defined and immediately called here
  if lambda(x)(4) < 0:
     print "a"
  elif y = 4:
     print "b"
     print "foo"

Where to stick the lambda body? It's not hard to come up with
straightforward answers, except that they are not particularly
appealing. One rule might be that the lambda bodies have to be placed
immediately after the statement body material, set off by the lambda:
thing. In the case of if/elif/else, they have to be placed behind the
closest suite that follows the expression in the syntax of the

  if lambda(x)(4) < 0:
     print "a"
     return x + 1
  elif y = 4:
     print "b"
     print "foo"

The overall rule is simple and uniform: each suite can have lambda:
clauses. These have to match lambda() occurences in the expression (or
expression list) immediately to the left in the same grammar

On the other hand, some people might find this compromise more
attractive: simply do not allow multi-line lambdas in compound

More information about the Python-list mailing list