http://xahlee.org/perl-python/python_3000.html
addendum, 20051001
here i will try to illuminate some miscellaneous things regarding the
lambda in Python issue.
as i have hinted (
http://xahlee.org/perl-python/list_comprehension.html ), the so-called
List Comprehension is just a irregular syntax to facilitate generating
lists. The name is a terrible jargon, and the means is also bent. The
proper name should be something like List Generating Form, and the
proper means should be the plain function.
For instance, Python's range() is such a list generator, only that it
is limited in scope.
For a example of a powerful list generator, see Mathematica's Table
function:
http://documents.wolfram.com/mathematica/functions/Table
Note Table's power in generating not just flat lists, but trees (nested
lists). And if one really want flat lists, there's the Flatten function
that flats any nested lists. (Python should have this too)
Python's reduce() is Mathematica's Fold. See
http://documents.wolfram.com/mathematica/functions/Fold
Besides Fold, there's FoldList, FixedPoint, FixedPointList, Nest,
NestList and others. FoldList is like reduce() except it returns a list
of each steps. FixedPoint recursively applies a function to itself
until the result no longer changes (or when a optional function returns
true) Nest is similar, except it does the recursion by a specified
number of times. The NestList and FixedPointList are similar except
that they return a list, containing all the steps.
All these can be written as a For loop, but they make the code
condensed and meaning clear. More so, they are important when
programing in a functional style. In functional programing, you don't
litter lots of variables or temporary functions or intermediate loops
here or there on every other line. The code is usually tight and
inline. When sequencing a series of functions, you can't stop in the
middle and do some loop or auxiliary calculation. All these are made
inline into a function. (that is: constructed as lambda) A block of
code usually corresponds to a unit of the algorithm used, as opposed to
a block of implementation. You don't read the minute details of the
code. You read the algorithmic unit's comments, or just the input and
output of a code block.
Also, these inline loop constructs are not only suitable for computing
numbers as Guido ignorantly thought. They are specialized forms of
generic loop constructs. Their first argument is a function, and second
argument is a list. Their generality lies with the fact that their
first argument is a function. If a language does not provide a
convenient way to represent the concept of a function, than these
functional loop constructs's usability will suffer.
The Pythoners, did not provide a convenient way to represent a
function. (they tried, with their limited implementation of lambda and
shun it like a plaque)
The way Guido puts it gives us a nice glimpse of their retarded
mentality:
«Also, once map(), filter() and reduce() are gone, there aren't a whole
lot of places where you really need to write very short local
functions;»
As we can see here, in Pythoner's mind, lambda is for “very short local
functions”.
Python's limited lambda and imperative programer's unfamiliarity of it
made functional programing suffer in Python. Consequently, it is not
surprising for one to feel a need to chop off things unfamiliar.
For Python's map(), look at Mathematica's Map on how it might be
extended.
http://documents.wolfram.com/mathematica/functions/Map
Note the ability to map to not just flat lists but trees (nested
lists). Note the power of expressing the concept of levels of a tree.
For Python's filter(), check out the equivalent in Mathematica's Select:
http://documents.wolfram.com/mathematica/functions/Select
Note how it provides a third option for picking just the first n items.
Also note, that Select is just a way to pick elements in a list.
Mathematica provides a set to do these: Part, Take, Drop, Select,
Cases, Delete, DeleteCases... All uniformly uses the function syntax
and all operate semantically by returning a new list. In Python and
other imperative clown's languages, usually they provide a limited
varieties to do such a task, and also inconsistent as if piled on.
(e.g. In Python we have alist[5:9], filter(f,alist), alist.remove(...),
del alist[...]. Some modify the list in-place, some returns a new
list.)
one is quite sorry to read a big shot contemplating on petty issues
with a ambitious name Python THREE THOUSAND.
For the grand Python THREE THOUSAND, what about supporting non-trivial
things such as exact fractions? What about a built-in worry-free
exact-arithmetics once for all? What about supporting pattern matching
for expression structures?
the features of Mathematica mentioned above existed over a decade ago.
But today, OpenSourcing bigwigs can contemplate and dither nothing but
which lipstick to use.
A good number of the industrial dignitaries are selfish liers. And
today we have the most human-labor intensive language Java and the
crazily hacked up Perl.
-------
This post is archived at:
http://xahlee.org/perl-python/python_3000.html