lua-users home
lua-l archive

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


On 7/1/2016 3:32 PM, Sean Conner wrote:
  There exist a few ways right now to construct a valid Lua sequence.  They
are:  ....

	x = {}	x[#x+1] = 1
		x[#x+1] = 2
		x[#x+1] = 3

This is the one that I probably use casually the most often, usually to assemble a large string from a bunch of computed bits and pieces which are then passed to table.concat().

It is also the form that has not been mentioned in this long thread so far.

IMHO, a very useful property of # on a table t is that it identifies a free slot named t[#t+1], whether t is a sequence or not. Proposals that force # to be constant would clearly break that property.

Now if we get a new "sequence" type, making # be immutable might be sane. A while back there was talk of making an n-tuple type which would be immutable once constructed like strings are. If that type existed, then ... would clearly be an instance of it.

IIRC, questions about what happens when an immutable ... is filled with references to mutable objects and other headache inducing edge cases became the enemy of the proposal and it went nowhere.

That said, a very simple fixed length array-like object would cover most of the use cases that stem from handling of ... and similar lists that can include gaps.

But it needs a name that helps reduce the user confusion. As does the internal implementation detail of the table's "array part" which keeps getting stirred into this discussion even though it has no place outside of the implementation of a table. So don't call the new thing "Array" unless you plan to take that bull by the horns.

--
Ross Berteig                               Ross@CheshireEng.com
Cheshire Engineering Corp.           http://www.CheshireEng.com/
+1 626 303 1602