lua-users home
lua-l archive

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


On 20 May 2010 02:59, Norbert Kiesel <nkiesel@tbdnetworks.com> wrote:
> Is deprecating ipairs really necessary?  I know it can be replaced for
> most parts with a numeric for loop, but these often look and feel
> clumsy.  There are a few other "syntactic sugar" constructs in Lua, so
> why is ipairs singled out?
>
> </nk>

I am very much against leaving ipairs in.
It is slow compared to a numeric for, and rarely required.
It is highly trivial to implement:
function inext ( t , k )
    if k == nil then return 1 , t [ 1 ] -- maybe you want to rawget?
your decision.
    elseif type(k) == "number" then return k+1 , t [ k + 1 ]
    else error("Bad index to inext")
    end
end
function ipairs ( t )
    return inext
end
(this has been untested)

5.2 breaks alot of compatability, and the removal of ipairs is a great thing.