lua-users home
lua-l archive

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




On Wednesday, September 17, 2014, Coda Highland <chighland@gmail.com> 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.
>
> 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. :-)

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.

/s/ Adam


I find the manual to be this way, generally.  It's extremely... efficient.  I'm *almost* smart enough to undrstand things on the first try. 

-Andrew