lua-users home
lua-l archive

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


I don't know if this makes things simpler or more complicated.

The behavior of pairs() on tables is defined in terms of next().

Imagine the behavior of ipairs() were defined by inext().

Several people have asked for a way to check if a table has a hash part, or non-integral keys. "Hash part" is just an internal implementation detail of tables, and it does not seem right to expose it. But I understand the desire not to walk through 1e4 numeric elements in order to find the string key "a".

What do useful non-array iterators, say, non_ipairs() and non_inext() look like? I see two alternatives:

1) non_inext() is defined as next() but skipping integral keys. Its implementation on raw tables ignores the array part entirely and just tests for non-integers in the hash part.

2) non_inext() is defined as returning all elements which would not be returned by inext().

Definition 2 may be interesting in clarifying what we want ipairs() to do.

Jay