[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pairs(t, skey) and ipairs(t, skey)
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 3 Oct 2013 23:43:22 -0300
> I'm unaware of any efficient way to iterate backwards through a sequence in Lua.
We're running in circles. A sequence in Lua has no holes and # returns
the number of elements in a sequence. So, to iterate backwards through a
sequence in Lua, just do
for i=#t,1,-1 do print(i,t[i]) end
ipairs and # are meant to be used on sequences and they work without
surprises on sequences. They are not useful for things that are not
sequences and may surprise some people in this case but they are
breaking the contract.
Can we move on now?
- 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
- Re: pairs(t, skey) and ipairs(t, skey), Tim Hill