lua-users home
lua-l archive

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


On Sat, Jan 9, 2010 at 12:37, steve donovan <steve.j.donovan@gmail.com> wrote:
> 2010/1/9 Ignacio Burgueño <ignaciob@inconcertcc.com>:
>>> 17. Documented behaviour of ipairs() is changed from "iterates until
>>> *first nil*" to "traverses table length elements as defined by length
>>> operator".

> This is more consistent, but given how strange #t is when t has a
> number of holes, it isn't necessarily more useful.

(1) Don't have holes in tables you want to measure with #, that's all.

> Mark's remark
> about pack/unpack being paired has some relevance here: pack() must
> set 'n', so why can't unpack() use it? Or ipairs?

And we're back to 4.x times?

I guess the problem is that if you accidentally have the "n" field
that is totally unrelated to the table size (which is and must be a
perfectly legal thing to do), you would not be able to do *anything*
(aside of changing the table) to prevent unpack() or ipairs() from
looking at it.

If we're going this way, then, better solution, perhaps, would be to
have a custom length "attribute" on a table, which would not be
neither a key nor a value.

But wait, now we're have one! The __len metamethod! Of course, this
has overhead of dealing with metatables, but, then, see (1).

Alexander.