diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-01-13 08:15:03 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2022-01-13 08:15:03 -0300 |
commit | 5d708c3f9cae12820e415d4f89c9eacbe2ab964b (patch) | |
tree | 055d2b85198f1a3a32b24527f94361421b9ce14f /manual | |
parent | 8dd2c912d299b84566c6f6d659336edfa9b18e9b (diff) | |
download | lua-5.4.4.tar.gz lua-5.4.4.tar.bz2 lua-5.4.4.zip |
Explanation of borders in the manualv5.4.4
The explanation includes the limit case of maxinteger being a border.
It also avoids the term "natural", which might include large floats
with natural values.
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 22 |
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 | ||
1981 | The length operator applied on a table | 1981 | The length operator applied on a table |
1982 | returns a @x{border} in that table. | 1982 | returns a @x{border} in that table. |
1983 | A @def{border} in a table @id{t} is any natural number | 1983 | A @def{border} in a table @id{t} is any non-negative integer |
1984 | that satisfies the following condition: | 1984 | that 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 | } |
1988 | In words, | 1989 | In words, |
1989 | a border is any (natural) index present in the table | 1990 | a border is any positive integer index present in the table |
1990 | that is followed by an absent index | 1991 | that is followed by an absent index, |
1991 | (or zero, when index 1 is absent). | 1992 | plus two limit cases: |
1993 | zero, when index 1 is absent; | ||
1994 | and the maximum value for an integer, when that index is present. | ||
1995 | Note that keys that are not positive integers | ||
1996 | do not interfere with borders. | ||
1992 | 1997 | ||
1993 | A table with exactly one border is called a @def{sequence}. | 1998 | A table with exactly one border is called a @def{sequence}. |
1994 | For instance, the table @T{{10, 20, 30, 40, 50}} is a sequence, | 1999 | For 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), | |||
1997 | and therefore it is not a sequence. | 2002 | and 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}.) |
1999 | The table @T{{nil, 20, 30, nil, nil, 60, nil}} | 2004 | The table @T{{nil, 20, 30, nil, nil, 60, nil}} |
2000 | has three borders (0, 3, and 6) and three holes | 2005 | has three borders (0, 3, and 6), |
2001 | (at indices 1, 4, and 5), | ||
2002 | so it is not a sequence, too. | 2006 | so it is not a sequence, too. |
2003 | The table @T{{}} is a sequence with border 0. | 2007 | The table @T{{}} is a sequence with border 0. |
2004 | Note that non-natural keys do not interfere | ||
2005 | with whether a table is a sequence. | ||
2006 | 2008 | ||
2007 | When @id{t} is a sequence, | 2009 | When @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 | ||
2017 | The computation of the length of a table | 2019 | The computation of the length of a table |
2018 | has a guaranteed worst time of @M{O(log n)}, | 2020 | has a guaranteed worst time of @M{O(log n)}, |
2019 | where @M{n} is the largest natural key in the table. | 2021 | where @M{n} is the largest integer key in the table. |
2020 | 2022 | ||
2021 | A program can modify the behavior of the length operator for | 2023 | A program can modify the behavior of the length operator for |
2022 | any value but strings through the @idx{__len} metamethod @see{metatable}. | 2024 | any value but strings through the @idx{__len} metamethod @see{metatable}. |