[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua 5.2 sequence definition - clarification needed
- From: David Kastrup <dak@...>
- Date: Wed, 29 Jun 2011 23:47:50 +0200
James Graves <firstname.lastname@example.org> writes:
> I would re-write that section as follows:
> Unless the __len metamethod is set, the length N is defined for a
> table which contains consecutive, positive integer keys from 1 to N
> and does not contain any positive integer keys outside the range 1 to
> N. Such a table is said to contain a 'proper sequence'.
> The following types of keys do not affect the length of the table and
> whether or not it contains a proper sequence:
> 0 (zero)
> negative integer (-1, -2, -55, etc.)
> non-integer (-1.3, 3.14159265, etc.)
Not a good idea since the transition between floats and integers is
fluid: the larger a value gets, the more likely a non-integer will get
rounded to an integer by accident. 3.14159265 is a noninteger, but
54325432543254325432543254325433.14159265 is likely an integer.
So I'd recommend just allowing for numeric keys <=0 as not affecting #
of the table.