lua-users home
lua-l archive

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

On Sun, 2022-01-09 at 12:18 -0500, Halalaluyafail3 wrote:
> This part of section 3.4.7 (The Length Operator) is very vague on what
> should happen when 'border' is the maximum integer:
> "
> The length operator applied on a table returns a border in that table.
> A border in a table t is any natural number that satisfies the
> following condition:
>      (border == 0 or t[border] ~= nil) and t[border + 1] == nil
> In words, a border is any (natural) index present in the table that is
> followed by an absent index (or zero, when index 1 is absent).
> "
> If the length operator is used on a table that has all positive
> integer indices and the minimum integer index set to a non-nil value,
> what should happen?

By tradition the length operator is only well defined for tables
which have content such that other programming languages would
refer to them as "an array". That is: strictly monotonic
increasing indices and content in all slots and no gaps between
them. Using the operator on something that is not an array has
never been reliable, and the documentation reflects that (the
result could be anything).

Now the question is: When you got an array where all slots are
filled and you reach max int as one of the valid indices -- have
you not already run into other problems before that? Like memory
exhausted or something?

virtually yours
Gerhard Sittig
     If you don't understand or are scared by any of the above
             ask your parents or an adult to help you.