Well this is an interesting and illuminating thread. But I think there's actually some confusion on what I was originally asking/suggesting.
> Does anyone know the rationale for not just automatically tracking the number of entries in a table?
This was meant to be a question about tracking the physical number of non-nil entries in the internal table data structure. So for instance, something like:
> print(numentries{1, nil, 3; foo="foo"})
would output:
> 3
and:
> print(numentries{foo="foo", bar="foo", baz="not foo!"})
would also output:
> 3
This could just be a simple get on an integer in the backing C struct. This neatly sidesteps the issue of whether a table is a proper sequence, since this doesn't address that question directly. I just want to know how many things there are in this table, at any key. This answers the question that you'd normally have to do something like the following to answer:
> local n = 0
> for k in pairs(t) do n = n+1 end
This being the case, most of the gotchas mentioned above seem to evaporate, and the only reason not to do that that I can see is that it makes *ALL* table writes a tiny bit more expensive. Probably something I'd implement as a power patch, if I was writing a lot of code that would benefit greatly from this.