lua-users home
lua-l archive

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


Am 13.09.2016 um 15:23 schrieb Peter Aronoff:
Here’s one that I consider a bit odd—and I’m testing my own understanding
now. The following *is* a sequence, according to the definitions in Lua’s
manual: {10, 20, nil}. That’s a sequence, and it’s length is 2. It’s
a sequence because there is an n such that “the set of [the table’s]
positive numeric keys is equal to {1..n} for some non-negative integer n.”
And that n (here 2) is it’s length. (Someone please correct me if I’m
wrong.) Presumably this means that {[1] = 10, [2] = 20, [3] = nil} is also
a sequence, although with a more verbose constructor.


Since a nil-value is indistinguishable from an unset key in a table, any trailing nils should be insignificant. That is, {10, 20, nil} is equivalent to {10, 20}. Using explicit keys should not change that.


‒ Christian