[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Accumulator
Pixel wrote:
> ...
> well, you didn't talk about "reduce". The main pb with list
> comprehensions is that they are limited to giving lists as a result.
reduce is used roughly once in the 50,000 lines of code that are the
Python standard library. It clearly is not pulling its weight. In a
project I worked on with six different Python programmers, ranging in
expertise from guru to newbie, nobody used it once.
"reduce" may be the right thing for Lisp programmers but we have
concrete proof that it is not the right thing for Python programmers.
That's why I strongly disagree with Paul G. that Python will grow more
Lisp-like over time. When it tried that, it failed.
>...
>
> but there are much simpler functions that can use lambdas (some
> examples are in ruby below):
Anything that can be done with lambda can be done without it, because
these two statements are equivalent:
_ = lambda y: y
def _(y):
...
Python's goal is regularity and readability, not succinctness.
Anyhow, let's suppose that you are right and I am wrong about the
uselessness of lambda. All of your examples of where lambda is
appropriate are places where all you need is Python's lambda (not a more
general block-holding, context-mutating lambda). If you want more, then
you probably are using lambda in a context that would make sense to a
Lisp programmer but not a Python programmer.
>...
> - manipulating data structures like XML trees: the "map" can transform
> an XML tree into another tree (a la XSLT)
Not if you mean the "map function".
Scheme: "The map procedure applies a given procedure to every element of
a given list, and returns the list of the results."
Python: "map(function, sequence)" calls function(item) for each of the
sequence's items and returns a list of the return values
Perl: "The map function evaluates the BLOCK or EXPR for each element of
LIST, locally setting the $_ variable equal to each element. It returns
a list of the results of each evaluation."
But if you mean that generally a function-oriented style of programming
can do XML transforms then yes this is true, whether or not you have
lambda, apply, filter, map and reduce. Python programmers have ways that
are better for them for solving all of the same problems in roughly the
same amount of code.
Paul Prescod