Re: Definition of a sequence
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Definition of a sequence
- From: Mike <lua-l@...>
- Date: 2015年6月11日 13:03:48 +0300
On 2015年6月11日 11:12:07 +0200
Oliver Kroth <...> wrote:
> Mike,
>
> the behaviour is unpredictable because it is defined to be not defined:
>
> > " 3.4.7 – The Length Operator
> > ...
> > Unless a __len metamethod is given, the length of a table t is only defined if the table is a sequence, that is, the set of its positive numeric keys is equal to {1..n} for some non-negative integer n. In that case, n is its length. Note that a table like
> >
> > {10, 20, nil, 40}
> >
> > is not a sequence, because it has the key 4 but does not have the key 3. (So, there is no n such that the set {1..n} is equal to the set of positive numeric keys of that table.) Note, however, that non-numeric keys do not interfere with whether a table is a sequence. "
> >
I see, it is reasoned. If we strictly follow the logic,
the length operator should ideally return nil in theese cases,
because "it usually represents the absence of a useful value".
--
- References:
- Definition of a sequence, Dirk Laurie
- Re: Definition of a sequence, Tim Hill
- Re: Definition of a sequence, Dirk Laurie
- Re: Definition of a sequence, Tim Hill
- Re: Definition of a sequence, Dirk Laurie
- Re: Definition of a sequence, Tim Hill
- Re: Definition of a sequence, "书呆彭, Peng Yi"
- Re: Definition of a sequence, Andrew Starks
- Re: Definition of a sequence, Mike
- Re: Definition of a sequence, Oliver Kroth