lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Yes, this is what I'm already doing, i.e. using tables instead and appending them.

I was just saying that it would be nice if the language allowed using double recursion with vararg lists. It would add to the possibilities of a functional approach, and even though the below code of course works it is often redundant since you prob normally end up with o(n^2) table insertions instead of o(n)...


________________________________________
Från: lua-l-bounces@lists.lua.org [lua-l-bounces@lists.lua.org] för Mateusz Czaplinski [czapkofan@gmail.com]
Skickat: den 16 juni 2011 09:48
Till: Lua mailing list
Ämne: Re: SV: pack/unpack

On Wed, Jun 15, 2011 at 5:39 PM, Fredrik Widlund <fredrik.widlund@qbrick.com<mailto:fredrik.widlund@qbrick.com>> wrote:
No, of course, I mean in the actual task (double recursion) I would want something like this

function f(...)
   (...)
   return f(...), f(...)
end

Which is not possible. I end up using appending tables etc. (Of course it's possible to remove the double recursion, or even recursion completely, but that's beside the point.)

Something like below? Your return line isn't a tail-call anyway, so it seems to have the functionality you wanted:

function f(...)
  -- ....
  local t = {f(...)}
  for _, v in ipairs{f(...)} do
    t[#t+1] = v
  end
  return unpack(t)
end

(disclaimer: not compiled)

greetings
Mateusz Czapliński