[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: local pre-declarations
- From: Asko Kauppi <asko.kauppi@...>
- Date: Wed, 1 Sep 2004 17:16:47 +0300
Now, that's fancy.. :) Thanks, I'll give it a go.
Other ideas I've come to think of:
local upfunc= {}
local function f
...
upfunc.g()
end
local function g
...
end
upfunc.g= g
..but this is not at all so elegant.
-ak
1.9.2004 kello 16:02, Gabor Grothendieck kirjoitti:
If the objective here is to get rid of the declaration then the
utility
function Recall defined in the first line below would allow you to do
it.
It calls the function n levels up on the stack so if f calls g and
g which calls Recall(2) then Recall(2) returns the function f.
Recall = function(n) return debug.getinfo((n or 1)+1,"f").func end
local g = function(x)
if (x > 0) then return x + Recall(2)(x-1) else return 0 end end
local f = function(x)
if (x > 0) then return x + g(x-1) else return 0 end end
print(f(3))