lua-users home
lua-l archive

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


2014-08-01 9:41 GMT+02:00 Philipp Janda <siffiejoe@gmx.net>:

> Is there a reason why the protocol for `ipairs` has changed from "iterate to
> first nil value" to "iterate to #table"? The first is well defined for all
> tables, and runs in O(n), while the second needs O(nlog(n)) time, requires a
> proper sequence for defined behavior, or can yield nil values during
> iteration.

The reason can only be "conceptual integrity". The Table library now
respects metamethods for setting and getting elements, it already
respected the length metamethod, so ipairs must clearly do that too.

I fear that some programs that relied on raw accesses in the table
library may now break, but I'm not going to argue this decision.
The Lua team gave, and the Lua team hath taken away;
blessed be the name of the Lua team.

But maybe conceptual integrity would still be served if an analogue
`inext` to `next` were to be available for traversing the raw numeric
keys of a table up to the first missing key. The manual's advice
(under `next`) to use the numeric `for` does not quite do the trick;
`for` up to where?