lua-users home
lua-l archive

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


> I was wondering what is the advantage in not enforcing a table without an
> array part to return a len of 0.

The reason why # does not return 0 or raise an error for tables that are
not sequences is that checking whether this holds can be expensive and
so # does something even for tables that are not sequences, though the
returned value is not useful.

Even if a table is a sequence, part of it may be stored in the hash part
and so the naive idea of maintaining the size of the array part does not
work (and this book keeping would be expensive as well).

All this has been discussed before at length :-)