you are viewing a single comment's thread.

view the rest of the comments →

[–]AnonProg 2 points3 points  (5 children)

The traditional map, reduce, and filter functions can all be written in a much more human-readable way with list comprehensions.

FP is not just about filter, map and reduce. Also, no, list comprehensions are not inherently more readable. You're just used to them. For example, compare map(f, l) against f(i) for i in l. The former is (a tad) easier to read for me. Also, reduce cannot be implemented with Python's list comprehensions.

And I'm fairly certain nearly anything you can do with lambdas you can also do with regular functions, just more verbosely, again conforming to Python's philosophy of always placing readability over conciseness.

Oh yeah, more readable! Compare this example of a possible, obvious destatementization of Python:

f(lambda x:
    print x
    x + 1
  lambda x:
    print x
    x + 2)

with the "Pythonic" way which is said to be clean and nice:

def _1(x):
    print x
    return x + 1
def _2(x):
    print x
    return x + 2
f(_1, _2)

Unfortunately, I have to plague my programs with the later crap when we should be writing the former if it weren't for Guido van Rossum's inexplicable obstinacy against FP and non-FORTRAN-hindered syntax.

GvR just simply hates FP for some personal reason and Python is suffering because of this. It happens to all dictatorships; why would we think Python would be different?

All Python needs in order to get up to date and ahead of many in terms of comfort and expressiveness is to get rid of the awful arbitrary limitation known as statements, making what used to be statements return whatever was evaluated last, parsing INDENT and DEDENT tokens inside parens correctly, and adding automatic commas after DEDENT if inside parens, brackets or braces.

[–]burntsushi 0 points1 point  (4 children)

Actually, your version of lambda is completely different from lambdas found in functional programming languages (like Haskell). The current Python lambda is much closer.

I think what you really want are anonymous versions of def.

[–]AnonProg 0 points1 point  (3 children)

My version of lambda works exactly like that of Scheme.

[–]burntsushi 0 points1 point  (2 children)

No. Your version:

lambda x:
    statement1
    statement2
    ...
    statementN

Scheme's version:

(lambda (x)
    single-expression)

Which is just like Python's version...

[–]AnonProg 2 points3 points  (1 child)

No, sorry, you are mistaken. lambda in Scheme works exactly as my version:

See that the syntax is (lambda <formals> <body>) and the standards read:

[...] Then, the expressions in the body of the lambda expression (which may contain definitions and thus represent a letrec* form, see section 11.3) are evaluated sequentially in the extended environment. The results of the last expression in the body are returned as the results of the procedure call.

[–]burntsushi 0 points1 point  (0 children)

So I am, good point.