Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]
Bengt Richter
bokr at oz.net
Thu Jul 7 12:45:31 EDT 2005
On 7 Jul 2005 15:46:23 GMT, Duncan Booth <duncan.booth at invalid.invalid> wrote:
>Steven D'Aprano wrote:
>
>> Put it this way: whenever I see a two-line def as above, I can't help
>> feeling that it is a waste of a def. ("Somebody went to all the trouble
>> to define a function for *that*?") Yet I would never think the same about
>> a lambda -- lambdas just feel like they should be light-weight.
>
>Obviously we think differently there. I don't see why lambdas are any
>different than single expression functions. I certainly don't think of them
>as lighter weight; they take just as long to call; and they involve just as
>much stack setup/tear down. On the other hand I don't consider functions as
>heavyweight, I'm happy to define short helper functions anywhere I think it
>makes the code more expressive.
>
>> Am I just weird?
>
>No, just different[*]. There's nothing wrong with different.
>
>[*] conclusion based entirely on your postings here. I have no evidence
>beyond that.
>
I think def is a form of assignment, with the target binding name
specified inside the expression syntax instead of to the left of an '=' as usual. I.e.,
def f(args): suite
is like
f = def(args): suite
except that I can't use an arbitrary left-hand side in the assignment, such as
MyClass.method = def(self, args): suite
or
somedict['foo'] = def(self, args): suite
Personally, I think def(args): suite ought to be allowed as an expression that you could
put in parentheses like any other expression if you need/want to write it with multiple lines.
Obviously this could both replace and expand the functionality of lambda ;-)
Regards,
Bengt Richter
More information about the Python-list
mailing list