Functional programming is possible in Python, but Lua makes it easy. Check out this code:
Lua |
---|
> infix = function(op) >> if op == "+" then return function(a, b) return a + b end >> elseif op == "-" then return function(a, b) return a - b end >> else return function() end >> end >> end > = infix("+")(10,5) 15 > = infix("-")(10,5) 5 > = infix("?")(10,5) > |
Lambda functions available in Python are the puny cousins of true anonymous functions. Because all functions in Lua are first-class values, Lua is more writable for functional programmers than Python.