[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 01:29:11 +0000 (UTC)
Matthew Wild <mwild1 <at> gmail.com> writes:
> On 16 April 2012 09:31, <csrl <at> gmx.com> wrote:
> > My point in this is that if #t returns a particular value n, it becomes
> > surprising if each key of {1..n} does not index a non nil value in the
> > table.
>
> It might be surprising, until you read the documentation.
Reading the documentation obviously did not clarify it for me, hence my post. :(
> > But in any case, I'd expect defined behavior rather than undefined
> > behavior. I can not wrap my head around how the above behavior might
> > be defined.
>
> Re-read the first sentence of the documentation you linked, especially
> the words "is only defined if". The documentation clearly says that
> the length of non-sequence tables is *not* defined. That means you
> cannot rely on it to give any particular value. It's not defined to be
> random either though, so don't use it for a random number generator :)
:) Thanks for attempting to clarify it, as for me "clearly" was not so clear.
To me the documentation stated that if the list was not a sequence that the
length of the table is not defined, meaning that it is nil. As that is not what
my testing showed me, instead it showed rather aberrant behavior which caused
confusion. Slightly better wording would have been to say that in such a case
the result of the length operator is 'undefined'.
> Dirk is right, this issue has been brought up many times - if you're
> interested in the background, reading the mailing list archives should
> be fairly educational. I answered your post in full mainly because
> it's the first question I've seen about 5.2 in particular, where the
> documentation was actually (hopefully!) clarified about this exact
> point based on all the discussions that have taken place about the
> same behaviour in 5.1.
Unfortunately not so on my part anyway. Thanks for taking the time to respond
here non the less.
chris