I ran into an interesting error today scripting at work.
fun = lambda x : print str(x)
The above Python code threw a syntax error, which took me a while to work out. To the Pythonista who keeps up, the problem is obvious: lambda functions only accept expressions, not statements. For those less familiar with functional programming, the difference between the two is that expressions can always be evaluated, while statements only yield side effects. In Python prior 3.0, 'print' is a statement, and returns no value, similar to 'while', 'for', and other built-in constructs.
def p(x):
print str(x)
fun = lambda x : p(x)
This time, the code runs. Why? The function p(x) doesn't explicitly return a value; instead, it implicitly returns 'None'. Unlike traditional imperative languages, Python doesn't draw a distinction between functions and 'procedures'- every function must return.
