lua-users home
lua-l archive

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


* Richard Hundt:

> Okay, so that brings us to the crux. The question is whether sparse
> tables are an implementation Artifact or a Feature.

Sparse tables are a feature.  However, the precise value of the length
operator is not defined for them; an implementation can arbitrarily
choose from a set of possible values.  This is clearly spelled out in
the reference manual (both in 5.1 and 5.2):

| The length of a table t can be any integer index n such that t[n] is
| not nil and t[n+1] is nil; moreover, if t[1] is nil, n can be
| zero. (All accesses are assumed to be raw for this description.) For
| a regular array, where all non-nil values have keys from 1 to a
| given n, its length is exactly that n, the index of its last
| value. If the array has "holes" (that is, nil values between other
| non-nil values), then #t can be any of the indices that directly
| precedes a nil value (that is, it may consider any such nil value as
| the end of the array).

<http://www.lua.org/work/doc/manual.html#3.4.6>