[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: manual improvement for next() [WAS: How undefined is undefined behaviour?]
- From: Viacheslav Usov <via.usov@...>
- Date: Fri, 11 Jun 2021 12:21:06 +0200
On Fri, Jun 11, 2021 at 6:37 AM Andrew Starks <email@example.com> wrote:
> The manual is totally clear and says everything you said in fewer words.
"Totally clear" is subjective, but this whole thread exists because
somebody apparently believed otherwise. I could say for myself that it
was not totally clear what behavior to expect when calling next() on
random keys, even though there was a clue in another place.
Then, the manual does not say "everything I said", unqualified,
because I have said things in my life that are not covered by the Lua
If qualified with "in the description given", then I count 144 words
in my description and 163 in the manual's.
> It is true that Lua's reference manual is very sparse.
As we have seen, there is a more concise description of next() than in
the manual, so this is not universally true. More on that later.
> I find myself needing to read it with extra care because it almost (?) never repeats itself.
Just in the description given, the manual repeats itself at least twice:
"When called ... with nil in an empty table, next returns nil" and
"you can use next(t) to check whether a table is empty".
"The behavior of next is undefined if, during the traversal, you
assign any value to a non-existent field in the table" and "You may
however modify existing fields" and "In particular, you may set
existing fields to nil".
I have seen in this list that certain people would treat the manual as
if it were a sacred text, not ever wrong and perfection itself, but
this is a fantasy, while the fact is that the manual does get
improved, and not always toward "sparseness". For example, the
description of the length operator: I am sure some would say that the
description given in v5.2 would be "sparse" and have "nothing
missing", but compare it with the description given in v5.4.