lua-users home
lua-l archive

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


On 10/3/13, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> I am not talking about implementation (hash part or array part) but about
>> table semantics. Lua table distinguishes sequential keys (from 1 through
>> N)
>> that can be iterated in order using ipairs from the other keys iterated
>> via pairs that visit all the keys in a non-specified order.
>
> That distinction does not come from Lua. It comes from mathematics.
>
> If I visit the keys starting from 1 (a math concept) and goes on
> increasing the key one by one (a math concept) until I find a nil value
> (a Lua concept not related at all with ipairs or numerical keys), then
> ipairs is born. There is nothing special in Lua to support ipairs.
>
> -- Roberto
>

All right, let us iterate backwards from last element of the sequence N down
to the first element 1 (also a mathematical concept).
How can I do it efficiently if I cannot rely on #length operator.
And I cannot rely on length-operator because there is no easy way to tell
whether a table has holes.

--Leo--