lua-users home
lua-l archive

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


> On Oct 1, 2013, at 19:16, Tim Hill <drtimhill@gmail.com> wrote:
>
>
> On Oct 1, 2013, at 11:57 AM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
>
>>> One of the incorrect assumptions I had was that ipairs(t) would
>>> produce the same keys as 1..#t, but it's clearly not the case as 1..#t
>>> may iterate over holes, but ipairs never does this (at least in Lua 5.1).
>>
>> The bottom line is: don't use #t or ipairs if you have holes in your table.
>
> .. and I know I'll get shot down for saying it again, but I still feel the lack of an efficient way to determine if a table t is a sequence is a significant hole in the language/runtime.
>
> --Tim
>
>

When I need this sort of thing, there always seems to be a way to get
it done. Sometimes:

T[object] = I
T[i] = object
...

Sometimes another table that gets updated using newindex, or bla bla bla.

All of these methods cost something, but then I can't see how that
"something" is any more or less efficient than something implemented
at the library level.

And then there is penlight.

I don't mean to take the honor of shooting anyone down. I just don't
see a super obvious, crazy-general data model that isn't easily
implemented with just a few lines of code.

The above is a sincere call for an example. :)

-Andrew