[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Self-awareness of functions?
- From: Dirk Laurie <dpl@...>
- Date: Thu, 30 Dec 2010 08:33:43 +0200
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