Let's Talk About Lambda Functions!

Steve Holden sholden at holdenweb.com
Mon Jul 29 11:05:52 EDT 2002


"John Roth" <johnroth at ameritech.net> wrote ...
> "Fredrik Lundh" <fredrik at pythonware.com> wrote...
> > Bryan Olson wrote:
> >
> > > The mistake was limiting lambda to expressions.
> >
> > Guido can channel himself (or Tim will do it), but from what
> > I can tell, he's always said that the "mistake" was adding
> > something to the language that almost, but not completely,
> > works like lambdas do in other languages.
> >
> > (lambda, map, filter, etc was contributed code)
> >
> > the really big usage problem (whether you knew lambdas
> > from other languages or not) used to be that they were a
> > real pain to use under the LGB scoping rule.  with the intro-
> > duction of nested scopes, that problem no longer exists.
> >
> > to fix the other "mistake", some needs to come up with a
> > really great syntax (and get michael hudson to implement
> > it for them ;-).  ideas are welcome.
>
> What's the problem with that? If we give up the notion
> that anonamous functions need to look like expressions,
> it should be simple. Just stick the function definition inline,
> indentation and all. The only issue is defining a new keyword,
> since lambda doesn't work that way. "def" would probably
> work, since it's only allowed at statement level now.
>
I'd like to see an example of this, since it appears you haven't fully
thought this through. You mean you'd like to be able to write some thing
like the following:

    for word in 'fee fie fo fum'.split():
        Button(frame, command=lambda:
            print word)

This is currently acceptable in Python because the lambda's inside a
parenthesised argument list. How would I add a second line to the lambda?
I'm always suspicious of phrasing like "all you need to do..." or "the only
issue...", since it often indicates that insufficient thought has gone into
a proposal. And the reason I'm suspicious when other people do it is because
I've watched me doing it enough to get into trouble!

Conclusion: this idea is currently 0.345-baked :-)

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list