_G.ipairs would no longer be needed and so using pairs on lists would ensure correct order while on tables it would not. We can also put _G.pairs in _G.list.pairs to allow the syntax "for i,v in mylist:pairs() do"
The list object would be constructed with the syntax [a,b,c] instead of {a,b,c} and can contain any value. However list keys are strictly numbered and ordered.
"mylist = table.tolist(tbl)" - for converting table to list if the table is valid.
"mylist = []" - to create a dynamically sized list.
"mylist = [1,2,3,4,nil,6]" - to create a list that is 6 in length.
Var args become a list object. Because of this I think "..." should be replaced with @. Here are some lua examples with the old method on top.
mytbl.varargs = table.pack(...)
======================
function foo(@)
mytbl.varargs = @
print(mytbl.varargs[1])
end
foo(42)
=======================
>> 42
local x,y,z = ...
======================
function foo(@)
local x,y,z = @:unpack()
print(x,y,z)
end
test(1,nil,2)
=======================
>> 1 nil 2
select(“#, ...”)
=======================
function foo(a,b,c,@)
print(#@)
end
foo(1,2,3,4,5,6,7,8,9)
=======================
>> 6
for i = 1, select(“#”, ...) do print(i, (select(i, ...))) end
=======================
function foo(@)
for i,v in @:pairs() do
print(i,v)
end
end
test(1,nil,2)
=======================
>> 1 1
>> 2 nil
>> 3 3
I believe this would simplify and make the language easier to understand.