lua-users home
lua-l archive

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


On Jun 1, 2013, at 11:36 AM, Jay Carlson wrote:

> On Jun 1, 2013, at 7:24 AM, Dirk Laurie wrote:
> 
>> When called with
>> an anonymous table, e.g.
>> 
>>  myfunc{1,2,3,4,5}
>> 
>> it is OK to modify the table and return it, but when called with
>> a table that already has a name, one must make a new copy
>> in case that name is referenced later.
>> 
>> Is there a way of diagnosing this difference?
> 
> No. Values do not have names; variables do.
> 
> I think you want something else: Do I hold the last reference to this table?

[...]

> I don't know how expensive it would be to ask for the GC's help in answering "is this the last reference". This is one of the few times reference-counting implementations win.

Oh, oops. In this case you don't need to ask the GC. The compiler can know the only reference to the table being constructed is the one being passed to myfunc.

Jay