better lambda support in the future?

Steven Bethard steven.bethard at gmail.com
Fri Dec 17 16:51:28 EST 2004


Michael DeHaan wrote:
> True enough, but suppose you want a hash of anonymous functions as
> opposed to just a lexical?

I've seen at least one reasonable example of this kind of thing:

http://mail.python.org/pipermail/python-list/2004-October/245432.html

Though I haven't yet seen an example that actually required lambdas with 
blocks...

> Totally agreed about a small use here and there, but they do have some
> use in dispatch tables, as they are a lot easier to read sometimes
> than very long case statements.    Of course, this would require
> multi-line lambdas to exist...

Certainly in the example above, I'd be willing to agree that the lambdas 
are at least as readable as a buch of def's above would have been.  I'm 
not sure if multi-line lambdas would be as readable though...  It all 
depends on what syntax you write them in -- you can see the struggle I 
went through in my other message...  Where do I put the commas in a 
dict?  Can't be at the end of the lambda or they turn the last 
expression into a tuple...  I resorted to putting them on a separate 
line, but of course there are other solutions.


If you have a good example of where you'd like to use multi-line 
lambdas, in, say, a dispatch table, I'd like to take a look at how you'd 
like to write them.  I'm not yet convinced that there really is a 
readable way to write such things...

Steve



More information about the Python-list mailing list