"Updating" lambda functions

Steven Bethard steven.bethard at gmail.com
Fri Sep 17 16:32:26 EDT 2004


Bengt Richter <bokr <at> oz.net> writes:
> On Fri, 17 Sep 2004 07:46:12 +0000 (UTC), I wrote:
> >
> >f = lambda args: body
> >
> >is equivalent to
> >
> >def f(args): body
> 
> Yes, but
> 
>    obj.f = lambda args: body
> 
> is possible without an intermediate local binding of f that might clobber a 
> previous f

Yeah, I probably should have been clear about that.  If 'f' is really just a 
name (as it was in my example) the two syntaxes I gave are equivalent.  If 'f' 
really isn't just a name, then you do still want an anonymous function.  In 
the OP's example though, 'f' really was just a name.

> Well, if lambda is removed (or not , I hope an anonymous def expression is 
> allowed...

Well, it's come up a number of times (one of the more recent is 
http://mail.python.org/pipermail/python-list/2004-June/226714.html), but it 
doesn't seem like there was any agreement on (a) what it should look like, or 
(b) why having such anonymous defs was such a gain over named defs.  If you'd 
like to champion a PEP about it...  ;)

Steve





More information about the Python-list mailing list