Last active
December 16, 2015 19:49
-
-
Save whoo24/5487280 to your computer and use it in GitHub Desktop.
Lua tuple by table and tail-call.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tuple(arg) -- arg is table. | |
local n_arg = #arg | |
if n_arg == 0 then | |
return nil; | |
end | |
if n_arg == 1 then | |
return arg[1]; | |
end | |
local function getTupleValue(n, idx, t_arg) | |
if n == idx then | |
return t_arg[idx] | |
end | |
return t_arg[idx], getTupleValue(n, idx+1, t_arg) | |
end | |
return arg[1], getTupleValue(n_arg, 2, arg) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment