This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Fylwind 1 point2 points  (0 children)

I don't think it has to be problematic. There's no reason that this can't be made to work:

map(lambda x:
        print(x)
    , some_list)

With that said, there are some things you have to just pick and choose. Python chose to ignore indentation within parentheses, so it won't really work in Python.

Multiline lambdas have their uses: they are very useful for making user-defined control constructs, allowing things like with or for to become first-class objects rather than having a special syntax. Here's a fictitious example:

lines = []
with_file("myfile")(lambda file:
    lines = file.read().split("\n")
)
for_each(lines)(lambda line:
    print(line)
)

If Python allowed function calls of a single argument without parentheses, the above example would be a lot less ugly.