lua-users home
lua-l archive

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


Hi,

> On Friday 14 June 2002 07:18, you wrote:
> > > In older versions of Lua, the 'next' function may return the elements of
> > > 't' out of order.
> >
> > That is not correct. Elements in a table has no order, so `next' cannot
> > return them out of (or in) order.
> >
> > -- Roberto
> 
> So as a rule, don't count on 'next'.  Even though the elements appear to be 
> ordered, one must remember that appearances can be deceiving!

Its easy to create an example where the entries show up in an order
that is not related to the ordering between numeric keys.

    Lua 4.1 (work3)  Copyright (C) 1994-2001 TeCGraf, PUC-Rio
    > y = {}
    > y[10] = 10
    > y[11] = 11
    > y[12] = 12
    > for i,v in y do print(i,v) end
    12      12
    10      10
    11      11

Regards,
Diego.

PS: Sparce vectors and dense vectors are represented differently. That's
the idea behind the example.