Skip to content

Instantly share code, notes, and snippets.

@whoo24
Last active December 16, 2015 19:49
Show Gist options
  • Save whoo24/5487280 to your computer and use it in GitHub Desktop.
Save whoo24/5487280 to your computer and use it in GitHub Desktop.
Lua tuple by table and tail-call.
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