On Sun, 4 May 2008 01:24:54 am Alex Martelli wrote:
> On Fri, May 2, 2008 at 11:32 PM, Mike Klaas <[EMAIL PROTECTED]>
> wrote: ...
>
> > Sorry, that was a bad example. It is obviously silly if the
> > return value of the function is callable.
>
> ...and yet it's *exactly* what keeps happening to lambda-happy
> programmers -- in production code as well as examples, and in
> major/famous projects too. E.g., a simple google code search shows
> many Zope versions containing "Bucket=lambda:{}" instead of the
> obvious "Bucket=dict",
In fairness, up until a few years ago, Bucket=dict wouldn't have worked.
I'm sure there's a lot of Python programmers who learnt the language
with version < 2.0 who still have blind-spots when it comes to types. I
know I do (but I'm getting better with practice).
Besides, would that be any better written as this?
def Bucket(): return {}
I think not. This is not a "named lambda" problem, this is a "developer
doesn't know how to use types" problem.
While we're discussing named lambdas, and at the risk of dragging this
thread out even longer, here's one example where I would use one:
def parrot(args, transformation=None):
if transformation is None: # Use an identity function.
transformation = lambda x: x
for arg in args:
do_something_with(transformation(arg))
Does anybody have any constructive comments to make about this usage?
--
Steven D'Aprano
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com