lua-users home
lua-l archive

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

David Kastrup <dak <at>> writes:
> I tried something like
> function x(...) return function()
>   for i=1, select('#', ...) do print(select(i,...)) end
> end end

For a detailed description of the limitations in expressivity when
using "varargs" (or, more generally, "expression lists" in the Lua
grammar), see the recently updated

I think it can be summed up as this: expression lists are awkward
to work with.  They are not first-class objects in Lua.  Tables
are more convenient to work with, but converting expression lists
to tables while preserving nil's is idiosyncratic,
{n=select('#',...),...}, and can be less efficient than necessary
due to the additional function calls, table construction, and possible
final unpack.

Allowing the above code (vararg as an upvalue) would increase
expressivity, and as Kristofer mentioned in this thread, operators
and opcodes for vararg manipulation may help somewhat, and some
have suggested immutable tuples as a solution.