Article of interest: Python pros/cons for the enterprise
Jeff Schwab
jeff at schwabcenter.com
Sat Feb 23 22:35:30 EST 2008
Paul Rubin wrote:
> Jeff Schwab <jeff at schwabcenter.com> writes:
>> So to use the Perl example: If you want to sort a list using some
>> arbitrary snippet of code as the comparison function, you can write:
>> sort { code to compare $a and $b } @elements
>
> Yes, you can do that in Python, using a lambda expression, a named
> function, or whatever.
You can indeed. I think you can also use this to do the other stuff you
would expect, e.g. return locally defined code snippets to define closures:
def mkadder(n):
return lambda x: x + n
I have gotten the impression that this was somehow inferior in Python
though, at least in terms of performance. Every time somebody uses
lambda here, they seem to get a bunch "why are you using lambda?"
responses. If I am grossly mistake, please just enlighten me.
>> What language do you have in mind, in which lambda is more basic than
>> named definitions? Are you coming from a functional language
>> background?
>
> All languages that I know of with lambda, treat it as more basic than
> named definitions, e.g. the Lisp family (not sure if those count as
> functional languages) in addition to functional languages like Haskell.
I note from your other posts that you seem to have a strong Lisp bent.
Lisp programmer and Smalltalk programmers stand out in the crowd. I
first noted this when somebody found a while-loop offensive, on the
grounds that recursion was somehow a more natural way to implement
looping. It can take a while to convince somebody like that they
different idioms work best in different languages.
More information about the Python-list
mailing list