lua-users home
lua-l archive

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


On Thu, Jun 16, 2011 at 09:48, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> On Thu, Jun 16, 2011 at 4:41 PM, HyperHacker <hyperhacker@gmail.com> wrote:
>> > Does that mean a table having keys 0, -1 or 1.5 no longer has a defined
>> > length?
>>
>> Would you mean a table just with keys like that, e..g {[0] = 1, [-1] =
>> 2}? Because there #t was always zero.  It seems that if the table has
>> an 'array part' (the [1..n] sequence) then #t gives the length of that
>> array part. Certainly a lot of code does assume that one can add
>> things to an 'array' in this way without upsetting the length
>> operator.
>
> We are considering the wording "positive numeric indices". So, indices
> 0 or -1 should not interfere with the sequence property. But I do not
> think that it is a good idea to allow indices like 1.5.
>
> -- Roberto
>
>

Mm, I'd expected fractional keys would be ignored completely (since
they won't be in the array part), but I can see why you'd want their
presence to make the length undefined.

There has been talk earlier on the list of renaming the standard
library "table" to "array" since all of its functions deal with
arrays. Perhaps 5.2 would be a good time to introduce this idea? You
could keep table=array for compatibility, and drop "table" a few
versions later.

-- 
Sent from my toaster.