lua-users home
lua-l archive

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


So getting back to my 3 questions…

1. Is there a need for an "empty" element within an array (where "empty" as a concept is tbd)?
2. Assuming #1 is "yes", would this be useful as a standardized technique so that everyone uses the same convention?
3. Assuming #2 is "yes", what form should this standard technique take?

You are arguing that the answer to #1 is "no"?

One thing that I find interesting is the amount of discussion here .. this is suggestive of *something* to be sure. Perhaps it's a misunderstanding of the problem, or perhaps there is *some* kind of problem here but people differ as to what it is.

One thing I like about Lua is the intuitive and clean nature of the language. But the Lua concept of a "sequence" to my mind is a bit odd .. it feels more like something that fell out of an internal optimization of table implementation (compact storage for integer keys and fast indexing) rather than a designed feature. This makes the # operator fragile; any 3rd party code or library can "corrupt" an array and make # return arbitrary invalid values and there is no way to discover this that I am aware of. I find this behavior a bit odd, and clearly some of the other posters do as well, as many suggestions here make # more robust (or provide a similar mechanism that is itself more robust).

Why is this relevant? Because my "empty" design (flawed as it might be) makes # more robust by providing a way to have them sparse but still a defined size, and the various other suggestions also do the same by other means.

--Tim

On Jul 5, 2013, at 1:24 PM, Andrew Starks <andrew.starks@trms.com> wrote:

Would never be seen by the garbage collector because nil isn't added to its list of stuff to track and 1 isn't explicitly constructed. [obj] = nil, because nil is now seen by gc as a weak object. 

If I'm saying this clearly, that behavior would also explain locals well, too. 

This behavior would, to my understanding, have avoided the need for another value and only require the need to know if something was set to nil or whether it was absent. 

That seemed cheaper than a new type and simpler to add. Since that's not how things are, I think that the way it works is fine, because everything else seems to make Lua "ever so slightly bigger."