[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: vararg asymmetry
- From: "John Belmonte" <jvb@...>
- Date: Sun, 4 Mar 2001 21:48:48 +0900
Michael Flad wrote:
> may not be the fastest way, but a recursive unpack should
> work?
"Wow, I didn't realize...". The recursion is unfortunate however since the
stack is already being chewed up passing the list. I still think expand is
useful enough to warrant an efficient implementation in the library.
Besides return arguments, it is also useful in place of call (when
protection is not required) because it's more readable. Consider:
call(myfunc, args)
versus
myfunc(expand(args))
Thanks for the tip,
-John
function expand_r(table, from, to)
if from < to then
return table[from], expand_r(table, from+1, to)
else
return table[from]
end
end
function expand(table)
return expand_r(table, 1, getn(table))
end
print(expand({"hey", 2, {}}))