1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
function f(x) return x + 1 end function g(x) return x*x end function compose(f,g) return function(x) return g(f(x)) end end print(compose(f,g)(1)) -- (x+1)(x+1) = (1+1)*(1+1) = 2*2 = 4 print(compose(g,f)(1)) -- (x*x)+1 = (1*1)+1 = 1+1 = 2
1 2
4 2