lua-users home
lua-l archive

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


Well, with different Lua version it MAY change the order, as far as I read this. Do not remember the implementation details at the moment thought.

On Sun, Oct 11, 2020, 13:41 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
>>How to comprehend "due to the way that Lua implements tables, the
>>order that elements appear in a traversal is undefined".
>>Could somebody explain that in more depth?
>"it's undefined" means "no guarantees are made about the order."
>The hope is that people will not rely on the order, then the
>implementation can be changed in the future without anyone's code
>breaking, because they did not rely on the order.
Thank you for your clarification.
Sorry, maybe I mislead you.

The sentence aforementioned is quoted from <<Programming in Lua>>(Page 38).
Here is the sentence followed [emphasise mine]:
The same program can **produce different orders each time it runs**.
The only certainty is that each element will appear once during
the traversal.

Why the same program may produce different orders each time it runs?

On Sun, Oct 11, 2020 at 6:12 PM Robert Burke <sharpobject@gmail.com> wrote:
>
> Hello,
>
> "it's undefined" means "no guarantees are made about the order." The hope is that people will not rely on the order, then the implementation can be changed in the future without anyone's code breaking, because they did not rely on the order.
>
>
> On Sun, Oct 11, 2020, 17:37 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
>>
>> How to comprehend "due to the way that Lua implements tables, the
>> order that elements appear in a traversal is undefined".
>>
>> Could somebody explain that in more depth?
>>
>> Best regards
>> Sunshilong