lua-users home
lua-l archive

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


On Fri, Dec 13, 2013 at 3:12 PM, Coda Highland <chighland@gmail.com> wrote:
> On Fri, Dec 13, 2013 at 1:04 PM, Andrew Starks <andrew.starks@trms.com> wrote:
>> On Fri, Dec 13, 2013 at 2:30 PM, Ulrich Schmidt <u.sch.zw@gmx.de> wrote:
>>> tablevar = setmetatable({}, getmetatable(tablevar))
>>
>> Kind of a sweet argument against a table.clear method existing at all,
>> but you'd have to revisit
>> http://lua-users.org/lists/lua-l/2013-11/msg00669.html for that
>> discussion, no?
>
> Calling back to the previous discussion:
>
> othervar = tablevar
> tablevar = setmetatable({}, getmetatable(tablevar))
> -- othervar still contains original table
>
> vs.
>
> othervar = tablevar
> table.clear(tablevar)
> -- othervar is empty now
>
> This is really the main reason why clear should exist. Everything else
> is just sugar -- this behavior is important.
>
> /s/ Adam
>


Yes, and while I was calling it a great argument against it, I too had
let this essential point to slip.

I'm puzzling it over again and am pretty sure that I still hope for a
`__clear` metamethod.

I'm surprised that table.clear would be considered, at all. I would
assume the response would be something like:

"Just do: for i in next, t do t[i]  = nil end"

:)

If it's mainly for optimization, then it should still be acknowledged
that people will use it as shorthand for the above.


-Andrew