I agree wholeheartedly with the first half of your comment, but the second half is the same uninformed dogma you rail against in the first!
Python is not really a functional programming language -- it has statements and suites, neither of which are first-class.
lambda is implemented as an inline (suite-less) value-returning statement (like the ternary statement) because dealing with indentation would be a bitch. Since statements cannot contain other statements outside of suites, it's impossible to implement full-fledged anonymous functions in the language grammar without breaking something.
While I'd love TCO in python, I like the stack traces better (ever dealt with a stray head [] in GHC?).
Python doesn't support creating anonymous functions, but functions are first-class. Sorry if you already knew this; it seems like you know Python pretty well so I'm sure you do.
Of course functions are first-class, and the lambda statement does return anonymous functions. Functions in Python are just objects that have a __call__ method, and methods are just functions partially-applied to the object they are bound on -- LOVELY METACIRCULARITY
What aren't first class are statements and suites (indented blocks of expressions) -- they're part of the syntax and thus can't be constructed or referred to. Particularly nasty is the way non-value-returning statements can't be used in expressions passed to other statements.
Your example is perfect -- in Python < 3, print is a statement and not a built-in function!
# this is invalid syntax:
name_printer = lambda x: lambda: print x
# with print as a function it works:
from __future__ import print_function
name_printer = lambda x: lambda: print(x)
I don't think I've ever used print that way. If I need to print more than one thing, it's clearer to use regular string formatting. Thanks for clarifying that though, interesting.
Python is not really a functional programming language -- it has statements and suites, neither of which are first-class.
lambda is implemented as an inline (suite-less) value-returning statement (like the ternary statement) because dealing with indentation would be a bitch. Since statements cannot contain other statements outside of suites, it's impossible to implement full-fledged anonymous functions in the language grammar without breaking something.
While I'd love TCO in python, I like the stack traces better (ever dealt with a stray head [] in GHC?).