lua-users home
lua-l archive

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


On Thu, Dec 30, 2010 at 07:44:22AM +0200, Henk Boom wrote:
> What about a utility function written purely in lua?
> 
> -----
> 
> function recursify(f)
>   local function g(...)
>     return f(g, ...)
>   end
>   return g
> end
> 
> fact = recursify(function (self, n)
>   if n == 1 then
>     return 1
>   else
>     return n * self(n-1)
>   end
> end)
> 
> -----

What three people tell me is true, to paraphrase the Bellman.
Your 'recursify' is what Drake calls the "Y combinator", also
posted by Wim.  It's the winner!

Dirk