lua-users home
lua-l archive

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


On Tue, Jan 11, 2011 at 6:04 PM, Frank Siebenlist
<frank.siebenlist@gmail.com> wrote:
> Could you please define your array semantics in more detail?

All that machinery is meant to stop holes getting into arrays. It's
true that arrays-with-holes have their uses, e.g. the common idiom to
handle nils in variable argument lists

function varargs(...)
   local args = {n = select('#',...),...}
   for i = 1,args.n do
     ...
  end
end

Which is what (I think) you would regard as an array, no problem, and
in fact this is now table.pack() in Lua 5.2.

But we cannot use ipairs() here, table.concat, table.sort, etc.  Holes
still feel like bad news to me and they can be largely avoided.

steve d.