lua-users home
lua-l archive

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


Op Wo., 26 Sep. 2018 om 20:19 het Egor Skriptunoff
<egor.skriptunoff@gmail.com> geskryf:
>
> On Wed, Sep 26, 2018 at 3:20 PM, Dirk Laurie wrote:
>>
>>
>> table.clear = function(tbl)
>>    local n=#tbl
>>    table.move(tbl,n+1,2*n,1)
>> end
>>
>
> Negative indices don't have "backwards" meaning in table.move(), so we can write more compact code
>
> table.clear = function(tbl)
>   table.move(tbl, -#tbl, -1, 1)
> end

I considered that possibility, but an array can have non-nils at
negative integer indices without violating the sequence property.