lua-users home
lua-l archive

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


2015-06-11 12:03 GMT+02:00 Mike <lua-l@inbox.ru>:
> On Thu, 11 Jun 2015 11:12:07 +0200
> Oliver Kroth <...> wrote:
>> > Unless a __len metamethod is given, the length of a table t is only defined if the table is a sequence,

> I see, it is reasoned. If we strictly follow the logic,
> the length operator should ideally return nil in these cases,
> because "it usually represents the absence of a useful value".

Detecting that a particular table is not a sequence, as has been
debated ad nauseam on this list, is an O(n) operation which you
can code for yourself if you really must have it.

> 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".

The value is useful, because it has the property that
   t[#t+1] = x
will store x into an empty slot. I wish that the documentation would
restore at least that half of the boundary property.