Why anonymity? [was Re: map/filter/reduce/lambda opinions andbackground unscientific mini-survey]

Terry Reedy tjreedy at udel.edu
Thu Jul 7 22:32:22 CEST 2005


The difference in readability between

func = lambda x: x**3 - 5*x

def func(x):
    return x**3 - 5*x

def func(x): return x**3 - 5*x

is obviously a matter of personal vision.

The fuctional difference (and, I believe, the only difference) is that the 
def form attaches the specific name 'func' to the function object as its 
func_name attribute while the lambda form attaches the generic 'name' 
'<lambda>'.   This makes tracebacks, for instance, less informative.

The reason some think the name=lambda form an abuse is that it is a second 
way to do almost the same thing (with the functional difference being a 
negative) while ignoring the intended purpose of lambda's presence in the 
language.  (But I will not argue this either way.)

Terry J. Reedy








More information about the Python-list mailing list