Theoretical question about Lambda

Alex Martelli aleax at aleax.it
Sun May 5 03:22:17 EDT 2002


Bengt Richter wrote:

> On Thu, 02 May 2002 21:05:45 GMT, Alex Martelli <aleax at aleax.it> wrote:
>>
>>I can't argue that lambda lets you do anything substantial that def
>>doesn't -- there would be just no basis to substain such an argument.
>>I'm curious to see what you think there might be.
>>
> I'm working on it ;-) "Substantial" does present an added hurdle ;-)

I originally thought this kind of situation might count as 'substantial':

funs = [ (lambda : x) for x in seq ]

i.e., the ability to use a list comprehension rather than a for/append loop
when the functions were simple enough.  But then of course I thought of
a closure-generating-and-returning auxiliary function:

def funize(x):
    def fun(): return x
    return fun

funs = [funize(x) for x in seq]

and *this* generalizes -- no "functions simple enough" constraint.


Alex




More information about the Python-list mailing list