lua-users home
lua-l archive

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


On Tue, May 25, 2010 at 1:09 AM, Stuart P. Bentley
<stuart@testtrack4.com> wrote:
> On Mon, 24 May 2010 17:04:53 -0700, Javier Guerra Giraldez
> <javier@guerrag.com> wrote:
>
>> On Sat, May 22, 2010 at 8:13 PM, Luiz Henrique de Figueiredo
>> <lhf@tecgraf.puc-rio.br> wrote:
>>>>
>>>> Take the behavior of ipairs(..) in Lua 5.1 and make it a special case
>>>> of pairs() in Lua 5.2. What is needed is simply that the language
>>>> guarantees that the iterator returned by pairs() will return the
>>>> values corresponding to the keys 1 and upwards in order. The order
>>>> before that, or the order of any keys after the first nil-valued
>>>> integer keys is arbitrary.
>>>
>>> This is messy to implement.
>>
>> i think the current next() implementation first checks the array part
>> and then the hash table.  doesn't this have the same effect?  or maybe
>> the guarantees are subtly different and dangerous to rely on?
>>
>>
>>
>
> Numbers aren't guaranteed to be in the array part.

Just as a solid example of this:

-- Make a table with hash part and array part
t = {1,2,3,4,a=5,b=6,c=7,d=8,e=9}
-- Empty the hash part
for k, v in pairs(t) do if v > 4 then t[k] = nil end end
-- Insert numbers, which end up in the hash part
for i = 5, 9 do t[i] = i end
-- t now has integer keys from 1 to 9 with no holes
for k, v in pairs(t) do print(k, v) end --> 123467859