lua-users home
lua-l archive

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


> The right question is not whether a table is a sequence, but whether
> the default #tbl is deterministic for the particular table, i.e. whether the
> table has no holes. Being a sequence is merely a sufficient condition. The
> iterations `for i=1,#tbl` and `for i in ipairs(tbl)` both ignore
> non-integer keys.

Sorry, but if you want to know whether '#tbl' has a reasonable meaning
(and is deterministic), then the right question is whether a table is
a sequence, because that is what the manual says:

  Unless a __len metamethod is given, the length of a table t is only
  defined if the table is a sequence, that is, the set of its positive
  numerical keys is equal to {1..n} for some non-negative integer n. In
  that case, n is its length.

The fact that the current internal implementation of '#' ignores
non-integer keys is an implementation detail.

-- Roberto