lambda functions ?

Maxim Veksler hq4ever at gmail.com
Mon Feb 5 17:06:57 EST 2007


Hello,
I'm new on this list and in python.

It seems python has some interesting concept of "ad hoc" function
which I'm trying to understand without much success.

Take the following code for example:

"""
>>> def make_incrementor(n):
... return lambda x: x + n
...
>>> f = make_incrementor(42)
>>> f(0)
42
>>> f(1)
43
"""

I really don't understand whats going on here.
On the first instantiating of the object "f" where does "x" gets it's
value? Or is it evaluated as 0? ie "x: 0 + 42"

And what is the "f" object? An integer? a pointer? an Object?
I'm coming from the C world...

Could some please try (if even possible) to implement the above code
without using "lambda" I believe it would help me grasp this a bit
faster then.

Thank you,
Maxim.


-- 
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?



More information about the Python-list mailing list