[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Does PIL (3rd edition) repeatedly misuse the length operator on tables and invoke undefined behavior?
- From: polyglot@...
- Date: Thu, 18 Sep 2014 06:01:20 +1000
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.
Just going by the 5.2 reference manual, I wouldn't know whether I
could depend on #table being 0 for an empty table. I'd have to peek
under the hood of each particular Lua implementation, and
portability wouldn't be assured.
PIL does a better job with this when it says "In particular, a
table with no [positive] numeric keys is a sequence with length
zero." I think such a direct statement in the normative reference
would be very helpful.
Anyway, practically speaking, I feel my question has been answered,
and I'll continue assuming my empty tables have length zero. :-)