lua-users home
lua-l archive

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


On 2014-09-18 06:48, Coda Highland wrote:
On Wed, Sep 17, 2014 at 1:01 PM,  <polyglot@openmailbox.org> wrote:
On 2014-09-18 05:17, Coda Highland wrote:


The difference between 0 and -42 in the aforementioned loop iteration
is that 0 is a cardinal number (that is, a number that can be used to
describe the size of a set), but -42 is not.


That's why 0 makes more sense than -42, but the trouble with undefined
behavior is that it's not required to do what makes more sense. The
length value of -42 for an empty table seems perfectly consistent
with the wording of the 5.2 reference manual.

I'm pretty sure you missed my point. The definition in the 5.2 manual
DOES explicitly say that an empty table has a length of 0. It doesn't
special-case it, but that IS a consequence of the definition
presented. It's not "you can assume it" -- it's "it's guaranteed." The
wording isn't ambiguous, just complicated.

I disagree.

n = 0 and n = -42 both satisfy the 5.2 reference definition of
a sequence. [1, 0] and [1, -42] in math are both empty sets/intervals.
1,0 and 1,-42 both produce an empty set with the Lua for loop you
originally offered to show why 0 'works'.

The qualification that a length be a cardinal number would indeed
resolve the problem, but this qualification is something *you've*
added. It's not in the 5.2 reference manual, AFAIK. The very fact
that the 5.3 manual adds the "non-negative" qualification for n
suggests that the 5.2 manual is lacking.