[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 'table' as fallback for tables
- From: Tim Hill <drtimhill@...>
- Date: Thu, 30 Jun 2016 22:32:02 -0700
> On Jul 1, 2016, at 4:30 AM, Martin <eden_martin_fuhrspam@gmx.de> wrote:
>
>
> On 16-06-30 05:11 PM, Tim Hill wrote:
>>> What about {1, [3]=3, 2} ? {1, [2]=2, 2} ? etc
>>>
>>
>> 2 and 2. The largest implicit key. As I said, this is the *least* surprising, not that it has no surprises at all.
>
> Huh. And what length of sequence should be after
>
> local t = {1, [2]=2, 2}
> table.remove(t, 2)
> --print(t[2])
> ?
>
> I think, better approach is to explicitly separate array part from hash
> part. But then we need separate indexing method for array part. Maybe
> syntax like "a.2" ?
>
First off, the "array part vs hash part" has nothing to do with this .. that is purely related to an internal optimization Lua uses in its implementation of tables. It’s a common mistake to suppose that t[2] is in the “array part” .. in fact in may be in the hash part or the array part (and it may be migrated dynamically as the table size changes). There is not need to introduce any new syntax.
Second, I’ve already noted in this thread that functions such as table.append() and table.remove() may need some revision. You can refer to my comments elsewhere if you like.
—Tim