lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

KHMan wrote:
From the little I know or understand of lambda calculus, it's
about anonymous functions.
One can use Y Combinator to implement recursion using only anonymous functions.

local function Y(f)
 function rec(...) return f(rec, ...) end
 return rec

local fac = Y(function(fac, n) if n == 1 then return 1 else return fac(n - 1) * n end end)

In fact one can turn Y in purely anonymous function. It is expensive, but possible. See Wikipedia or some good old book (e.g. Essentials of Programming Languages) for more details.