lua-users home
lua-l archive

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





On Fri, Aug 1, 2014 at 1:00 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> It was mentioned that "table.clear" (or similar) was likely. Was it decided
> that it would not be useful?

I don't think we even agreed on what it would do.

-- Roberto


The only negative I found was disagreement on why one would want it.

Primary example:

Shared state container between two entities that needs to be reset. As it is, the solution would be to store the state inside another table and replace that table. It'd might be better to clear it, thus creating less trash and allowing me to more concisely represent what i'm doing.

Another example, which was the source of comment by Mike:

A pretty printer that needs to track tables that have already been traversed. I would store the tostring(t) (assuming no __tostring) in a table as `visited[tostring(t)] = true`. 

When done, I would clear the table. As it is, i would make the table new, every time because I would assume that looping and nilling the values would take more time that trashing the table.


This is not something I care a great deal about, as I don't have enough in-the-field experience with Lua. In my benchmarking thus far, garbage collection has not been an issue. So this would come down to a nice convenience feature.

-Andrew