[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 Length Operator and tables (bug?)
- From: chris <csrl@...>
- Date: Tue, 17 Apr 2012 00:54:00 +0000 (UTC)
Luiz Henrique de Figueiredo <lhf <at> tecgraf.puc-rio.br> writes:
>
> > 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
I would be interested to understand the intended purpose of the length operator
for tables then. As I see it, you have to know that the table is a sequence in
order to find the length operator useful. If you know it is a sequence, that
means you could have already tracked the length manually (which is the suggested
course of action, according to the luafaq.org, when you know it is *not* a
sequence).
As the table.* api appear to be useful for working on tables made of sequences,
I would venture to pose that a table.len() function be more appropriate exposure
of this functionality, and less ambiguous of purpose.
chris