Just curious, but from a pragmatic view, what is the advantage of using anonymous functions instead of named functions for any mildly complex code?
val = my_list.reduce(foobar)
What is even going on here?For example, Python's with statement could have been entirely programmed as a library function if lambas supported code blocks:
with(open("file.txt"), lambda f:
content = f.read()
return sum(int(c) for c in content.split(" "))
)
Functional languages usually have a pretty limited "core" and implement most of their features through their standard library, usually using higher-order functions, overloaded operators ... def _(f):
content = f.read()
return sum(int(c) for c in content.split(" "))
with(open("file.txt"), _)