lua-users home
lua-l archive

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

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.