Re: Parsing varargs to a function
'Lars Müller' via lua-l <[email protected]> Tue, 28 Apr 2026 15:53:17 +0200
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Martin, Yes, you're right that most of the time, it doesn't matter much as you have something like a couple dozen arguments at most. (And if you expect to have more, you should strongly consider a table.) But this is a "you can have your cake and eat it too" situation. There is no real need for a tradeoff here. From a language design perspective, there should be a canonical construct which lets you correctly and efficiently iterate varargs. I want to be able to tell programmers "just use this way of iterating varargs" in a style guide. The programmer should not need to think "hmm, this vararg will probably always be small enough that quadratic time is okay", which generally can't be ensured when you're writing, say, library code. And so I find it nice to see that at long last, this "canonical iteration" has been made a thing :) - Lars On Tue, Apr 28 2026 at 01:02:15 +02:00:00, 'Martin Eden' via lua-l <[email protected]> wrote: > > On 2026-04-27 22:57, Lars Müller wrote: >> Personally I would have preferred a (peephole-ish) optimization that >> makes >> "x = select(i, ...)" constant time, as found in LuaJIT. >> Then the "select"-loop would be fine as idiomatic vararg iteration >> construct. >> (In its current state, it runs in quadratic time on PUC Lua, as >> varargs >> with (average) linear length are copied on the stack in every >> invocation. >> For older versions of PUC Lua, I thus recommend iterating tables by >> first >> packing them up using table.pack and then iterating up to t.n >> instead.) > Hello Lars, > > I don't care about performance of PacMan's bait "...". > > I use "..." mostly to wrap results of function passed as argument. > So there is unlikely be 20 M values from function. And O(N) > get_by_index(index, ...) is okay. > > -- Martin > > -- > You received this message because you are subscribed to the Google > Groups "lua-l" group. > To unsubscribe from this group and stop receiving emails from it, > send an email to [email protected] > <mailto:[email protected]>. > To view this discussion visit > <https://groups.google.com/d/msgid/lua-l/5e68c2c2-aa8d-4f01-b67b-65d8332b3246%40disroot.org>. -- You received this message because you are subscribed to the Google Groups "lua-l" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/lua-l/TKI7ET.07GM2F3ZOAZG1%40gmx.de.