lua-users home
lua-l archive

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


On 13/12/2010 11.14, Axel Kittenberger wrote:
Likely I'm a bit naive about this. But couldn't we just define for #
operator to simply return the size of the array part?

Meaning counted from 1 onwards # to defined the the largest numeric
key where t[k] is not nil. t[#t+1] is nil.

I'd be happy with that, but (apart from other people having different wishes) consider what will happen if you have a table such as:

 t = { 1, 2, 3, nil, 5, 6, 7, ... } -- a very very large table

#t would be 3.
Now fill the hole:

 t[4] = 4

To update #t correctly according to your definition, all the remaining length of the array would probably have to be traversed sequentially.

--
  Enrico