[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ... can't be upvalue?
- From: David Manura <dm.lua@...>
- Date: Sat, 1 Sep 2007 02:17:29 +0000 (UTC)
David Kastrup <dak <at> gnu.org> 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
http://lua-users.org/wiki/VarargTheSecondClassCitizen
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.