lambda

Ulf Bartelt (stub@pce60.rz.tu-clausthal.de)
30 Sep 1994 07:57:39 GMT

Jeff Dalton (jeff@aiai.ed.ac.uk) wrote:
: >
: > def make_incrementor(n):
: > return lambda(x, incr=n): x+incr

: Can someone who knows Python explain what this does / how it works?

: My guess is that the value of n is textually substituted for "n" in
: "return lambda(x, incr=n): x+incr". But I know nothing of Python.

First: the parentheses are wrong.

Use (lambda x,incr=n: x+incr) instead.

If interested in lambda, have a look at sectio 4.13 of the FAQ (v1.12).
Maybe this is a different number in the new FAQ but plusminus some subtopics
it's lambda's corner...

Bye !
Ulf.

--
Ulf Bartelt | 2:2437/120.666@fidonet.org | bartelt@sun2.isaf.tu-clausthal.de
            |                            | stub@linux.rz.tu-clausthal.de