What do you mean by "usable function literals"? Because Python has them, even if you have to do a bit of work to get them.
def demo (n):
def multiplier (m):
return n * m
return multiplier
x5 = demo(5);
print x5(4)
You can do anything in the inner closure that you might want. The only surprise is scoping - if you want to modify state you need to use a mutable data type because otherwise you'll be instantiating a private variable. But that hoop is easy to handle.
But, you say, you really want anonymous classes? Well look up metaprogramming then. Python really has quite good support for it. There is no trouble creating anonymous classes on the fly with their own attributes, functions, and so on. They can even inherit from each other. http://www.voidspace.org.uk/python/articles/metaclasses.shtm... might be a good starting place on this for you.
(Note, I do not recommend metaprogramming unless the solution you make will be reused a lot.)
lambdas. Your example isn't a literal, it's just a declared function named "multiplier". Sure, it has equivalent functionality, in the same sense that Python could remove collection literals like [1,2,3] and you could still create lists and maps by hand. But that would be silly.
even if you have to do a bit of work to get them
And that work means that useful techniques become too unwieldy to use in practice.
I am also annoyed by the omission of a truly useful lambda. But the rest of the language is compact enough that I've never found techniques relying on closures to be unwieldy in Python. shrug
My similar solution is here https://gist.github.com/3678958 it has the added bonus of using an object with the methods attached, but the outcome is the same.
But, you say, you really want anonymous classes? Well look up metaprogramming then. Python really has quite good support for it. There is no trouble creating anonymous classes on the fly with their own attributes, functions, and so on. They can even inherit from each other. http://www.voidspace.org.uk/python/articles/metaclasses.shtm... might be a good starting place on this for you.
(Note, I do not recommend metaprogramming unless the solution you make will be reused a lot.)