|
On 13/12/2010 13.10, David Kastrup wrote:
t = { 1, 2, 3, nil, 5, 6, 7, ... } -- a very very large table #t would be 3. Now fill the hole: t[4] = 4 To update #t correctly according to your definition, all the remaining length of the array would probably have to be traversed sequentially.Why? t[4] = 4 will presumably just increase the array part by one, resulting in #t == 4.
Why? From the user's point of view, the table will then be a proper array with non-nil indexes from 1 to (a possibly very large) n, so the user will expect #t to return n. Having it return any other value will be confusing and, practically speaking, nondeterministic.
(or maybe I missed your point)By the way, I'm not advocating any change to the current #t implementation, just writing for the sake of discussion, which could perhaps lead to interesting ideas for a future Lua version.
-- Enrico