lua-users home
lua-l archive

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


Are there plans to support either assignment to ... or
... as an upvalue?

If not, then we don't need the explicit ... notation
in an argument list?  The only real use would then be
an optimisation hint to the compiler that it can also
easily figure out by itself.

Since ... is immutable, the ... as upvalue could be
realised as a constant array part in a closure (a bit
like upvalues in C closures).  It would also provide a
cool way to realise immutable tuples in Lua (still not
internable of course):

-- shamelessly stolen from an example of Rici...
function tuple(...)
    return function(f)
        return f(...)
    end
end

local function car(x) return x end
local function cdr(_, ...) return ... end

local t = tuple(10, 20, 30, 40)

-- nargs returns the number of arguments...
print(t(nargs))  -- 4
print(t(car))  -- 10
print(t(cdr))  -- 20  30  40


--
Wim

PS (unrelated):  Can anyone show a sensible example
where you'd like to use a weak-valued immutable tuple?



		
_______________________________
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush