[BangPypers] BangPypers Digest, Vol 6, Issue 8

Prashanth munichlinux at gmail.com
Mon Feb 18 12:44:13 CET 2008


hi

On Feb 18, 2008 4:09 PM, Ramaswamy, Vivek <Vivek.Ramaswamy at fmr.com> wrote:
> Hello~
>
>
> >>> g=lambda m:lambda: ++m
> >>> incre=g(0)
> >>> incre()
> 0
> >>> incre()
> 0
> >>> incre()
> 0
> >>>
>
> I would want each call to incre() increase the value by one.
>

i dont understand why you call incre()(is that a function call?)  the
one you are doing is something like
a = 0
print a
0

I think you like to do something like this

>>> def make_incrementor (n): return lambda x: x + n
>>>
>>> f = make_incrementor(2)
>>> g = make_incrementor(6)
>>>
>>> print f(42), g(42)
44 48
>>>
>>> print make_incrementor(22)(33)
55

-- 
regards,

Prashanth


More information about the BangPypers mailing list