aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
Diffstat (limited to 'manual')
-rw-r--r--manual/manual.of22
1 files changed, 12 insertions, 10 deletions
diff --git a/manual/manual.of b/manual/manual.of
index c660215c..15f207fa 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -1980,15 +1980,20 @@ character is one byte.)
1980 1980
1981The length operator applied on a table 1981The length operator applied on a table
1982returns a @x{border} in that table. 1982returns a @x{border} in that table.
1983A @def{border} in a table @id{t} is any natural number 1983A @def{border} in a table @id{t} is any non-negative integer
1984that satisfies the following condition: 1984that satisfies the following condition:
1985@verbatim{ 1985@verbatim{
1986(border == 0 or t[border] ~= nil) and t[border + 1] == nil 1986(border == 0 or t[border] ~= nil) and
1987(t[border + 1] == nil or border == math.maxinteger)
1987} 1988}
1988In words, 1989In words,
1989a border is any (natural) index present in the table 1990a border is any positive integer index present in the table
1990that is followed by an absent index 1991that is followed by an absent index,
1991(or zero, when index 1 is absent). 1992plus two limit cases:
1993zero, when index 1 is absent;
1994and the maximum value for an integer, when that index is present.
1995Note that keys that are not positive integers
1996do not interfere with borders.
1992 1997
1993A table with exactly one border is called a @def{sequence}. 1998A table with exactly one border is called a @def{sequence}.
1994For instance, the table @T{{10, 20, 30, 40, 50}} is a sequence, 1999For instance, the table @T{{10, 20, 30, 40, 50}} is a sequence,
@@ -1997,12 +2002,9 @@ The table @T{{10, 20, 30, nil, 50}} has two borders (3 and 5),
1997and therefore it is not a sequence. 2002and therefore it is not a sequence.
1998(The @nil at index 4 is called a @emphx{hole}.) 2003(The @nil at index 4 is called a @emphx{hole}.)
1999The table @T{{nil, 20, 30, nil, nil, 60, nil}} 2004The table @T{{nil, 20, 30, nil, nil, 60, nil}}
2000has three borders (0, 3, and 6) and three holes 2005has three borders (0, 3, and 6),
2001(at indices 1, 4, and 5),
2002so it is not a sequence, too. 2006so it is not a sequence, too.
2003The table @T{{}} is a sequence with border 0. 2007The table @T{{}} is a sequence with border 0.
2004Note that non-natural keys do not interfere
2005with whether a table is a sequence.
2006 2008
2007When @id{t} is a sequence, 2009When @id{t} is a sequence,
2008@T{#t} returns its only border, 2010@T{#t} returns its only border,
@@ -2016,7 +2018,7 @@ the memory addresses of its non-numeric keys.)
2016 2018
2017The computation of the length of a table 2019The computation of the length of a table
2018has a guaranteed worst time of @M{O(log n)}, 2020has a guaranteed worst time of @M{O(log n)},
2019where @M{n} is the largest natural key in the table. 2021where @M{n} is the largest integer key in the table.
2020 2022
2021A program can modify the behavior of the length operator for 2023A program can modify the behavior of the length operator for
2022any value but strings through the @idx{__len} metamethod @see{metatable}. 2024any value but strings through the @idx{__len} metamethod @see{metatable}.