lua-users home
lua-l archive

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


2014-08-01 17:15 GMT+02:00 Daurnimator <quae@daurnimator.com>:
> On 1 August 2014 10:48, Roberto Ierusalimschy <roberto@inf.puc-rio.br>
> wrote:
>>
>> >  [...] However, I am not delighted
>> > by an optional argument preceding a non-optional one. [...]
>>
>> We do not like it either. Do you suggest any alternative?
>>
>> -- Roberto
>>
>
> I see no problem saying making the function signature
>
>     table.icopy(from_tbl, from_idx, num_elements, [to_tbl, to_idx])
>
> If to_tbl and to_idx ar not given, they default to the empty table and 1.
> The function always returns to_tbl.

I like this, but why not

table.icopy(from_tbl[, from_idx, num_elements[, to_tbl, to_idx]])

with from_idx, num_elements defaulting to 1,#from_tbl? Then
sequence cloning is simply

to_tbl = table.icopy(from_tbl)