[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A question about table's length
- From: David Manura <dm.lua@...>
- Date: Tue, 29 Dec 2009 22:45:04 -0500
On Tue, Dec 29, 2009 at 7:48 AM, Vaughan McAlley wrote:
> It allows for an efficient implementation of the # operator.
I thought I would mention that the following two loops do not have the
same output:
t = {1,nil,2}
for i,v in ipairs(t) do print(v) end --> 1
for i=1,#t do print(t[i]) end --> 1 nil 2 (maybe)
This leads to an open question if you want to implement a function
like [1] that is to separately deal with the array and hash parts of a
table. To implement such functions robustly and generally, we need to
specify whether values like 2 above are to be considered in the hash
part or array part, and we need to be careful how we iterate.
[1] http://snippets.luacode.org/sputnik.lua?p=snippets/Iterating_over_the_hash_part_of_a_table_6