lua-users home
lua-l archive

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


It was thus said that the Great pocomane once stated:
> On Wed, Mar 14, 2018 at 7:24 PM, Roberto Ierusalimschy
> > 
> > I think we cannot use a value to represent the absence of a value, no
> > matter how many no-value values we add. It is a contradiction. Several
> > languages followed this path, always with bad results.
>
> Ok, but, How Much Does it Cost? (sic)
> 
> New keyword. Two way to express the emptyness (one for functions, one
> for tables, completly different).
> 
> And, honestly, the ones that are confused about the "Sequences with
> holes" will be less confused about

  Perhaps much like Lua 5.3 split numbers into numbers and integers, it's
time for Lua to split tables into tables and true arrays?  Get rid of the
whole "sequence" thing and make the array length O(1).  To get the
discussion going, the following can be used to create such an array:

	x = { 1 , 2 , 3 } -- true array
	y = table.array() -- an empty true array

  The construction like:

	z = { [1] = 1 , [2] = 2 , [3] = 3 }

produces the traditional Lua table (make it easier on the parser).  As a
transition, optionally keep #z (traditional definition of sequence) but mark
it obsolete (unless the table has a __len metamethod defined).  This means
that:

	a = { nil , nil , nil }

has a length of 3.  To remove items, you do a table.remove() (or perhaps an
array.remove()?  Discuss!).  To insert, table.insert() (or array.insert()).

  In thinking things over, I don't like the undef idea.  I think it
introduces too many issues.

  -spc