Proper tail recursion in core.save_unpack()
This commit is contained in:
parent
faa295651a
commit
6f46983115
1 changed files with 7 additions and 4 deletions
11
core.lua
11
core.lua
|
@ -53,10 +53,13 @@ local function save_pack(...)
|
||||||
return {n = select('#', ...), ...}
|
return {n = select('#', ...), ...}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function save_unpack(t, i)
|
local function save_unpack_helper(t, i, ...)
|
||||||
i = i or 1
|
if i <= 0 then return ... end
|
||||||
if i >= t.n then return t[i] end
|
return save_unpack_helper(t, i-1, t[i], ...)
|
||||||
return t[i], save_unpack(t, i+1)
|
end
|
||||||
|
|
||||||
|
local function save_unpack(t)
|
||||||
|
return save_unpack_helper(t, t.n)
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue