"Updating" lambda functions
Terry Reedy
tjreedy at udel.edu
Fri Sep 17 19:33:09 EDT 2004
"Bengt Richter" <bokr at oz.net> wrote in message
news:cie73b$jma$0$216.39.172.122 at theriver.com...
>>> "Terry Reedy" <tjreedy <at> udel.edu> wrote in message
>>> news:mailman.3428.1095385637.5135.python-list <at> python.org...
>>>
>>> | I am curious if there is any reason other that habit carried over
>>> from
>>> | other languages to not write the above as
>>> |
>>> | def fu(x): return x
>>> | def fu(x): return fu(x) + 17
>
> obj.f = lambda args: body
>
> is possible without an intermediate local binding of f that might clobber
> a previous f, as in
>
> def f(args): body
> obj.f = f
> del f # if you want to clean up. But better save the old f in that
> case?
>
> I'd rather use lambda.
Thanks. I had not thought of this variation. Similar would be
seq[n] = lambda <whatever>
Of course, I *might* prefer being able to write
def obj.f(params): <etc> # and
def seq[n](params): <etc>
Since def is effectively a binding statement, name to function object (like
import, name to module), these seem not entirely unreasonable to me.
Terry J. Reedy
More information about the Python-list
mailing list