[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pairs(t, skey) and ipairs(t, skey)
- From: Tim Hill <drtimhill@...>
- Date: Thu, 3 Oct 2013 19:33:01 -0700
On Oct 3, 2013, at 7:15 PM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
>> 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.
>
> No, Lua makes no such distinction. ipairs does because it provides a view
> of the table as a sequence.
But it doesn't. ipairs() just iterates until it hits the first nil, regardless of any subsequent numeric keys. The Lua reference quite clearly defines a sequence such that additional numeric keys after a nil are not allowed (or, equivalently, that there are no "holes" in the sequence). ipairs() really has nothing to do with sequences so far as I can see.
I'm unaware of any efficient way to iterate backwards through a sequence in Lua.
--Tim
- References:
- pairs(t, skey) and ipairs(t, skey), Andrew Starks
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- Re: pairs(t, skey) and ipairs(t, skey), Tom N Harris
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- Re: pairs(t, skey) and ipairs(t, skey), Leo Razoumov
- Re: pairs(t, skey) and ipairs(t, skey), Roberto Ierusalimschy
- Re: pairs(t, skey) and ipairs(t, skey), Leo Razoumov
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo