[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: function foo() in table
- From: Sean Conner <sean@...>
- Date: Mon, 21 Apr 2014 17:33:48 -0400
It was thus said that the Great Coroutines once stated:
>
> I always remember that local function f() ... end is equivalent to
> local f; f = function () ... end because when I have to write
> recursive functions it errors when it tries to call the
> not-yet-declared identifier from within itself.
You should try using the Y combinator.
function Y(f)
local function g(...) return f(g,...) end
return g
end
print(Y(function(rec, x)
if x < 2 then
return 1
else
return x * rec(x-1)
end
end)(5))
-spc (Unfortunately, do declare Y with your conding standard requres the
use of Y ... )