[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (alpha) now available
- From: Romulo <romuloab@...>
- Date: Sun, 12 Dec 2010 17:57:12 -0200
Array with holes are not arrays in Lua, they are hash tables. That simple.
Thus, if t[ 1 ] is nil, then #t is zero, even if different
implementations may give other results. Specially if others
implementations give different results.
I wonder why people can't just accept it.
On 12/12/10, Geoff Leyland <geoff_leyland@fastmail.fm> wrote:
> On 13/12/2010, at 8:30 AM, Enrico Colombini wrote:
>
>> On 12/12/2010 19.57, Geoff Leyland wrote:
>>> t[1] is quicker than #t> 0, especially if t is a long array.
>> > (Not my idea, Javier Guerra pointed this out in
>> > http://lua-users.org/lists/lua-l/2008-03/msg00540.html)
>>
>> Interesting... I always thought #t required constant time.
>> However, t[1] is not equivalent to #t if the 'array' has a hole in t[1].
>
>
> But it might be equal for some cases :-)
>
> lua
> ...
>> t = {}
>> t[2] = 2
>> = #t > 0
> false
>> = t[1]
> nil
>
> luajit-2.0.0-beta5
> ...
>> t = {}
>> t[2] = 2
>> = #t > 0
> true
>> = t[1]
> nil
>
>
>
--
Sent from my mobile device