lua-users home
lua-l archive

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


Hi Steve,

Sorry to be somewhat pedantic, but I'd like someone to define the array semantics in detail.

Much of the confusion that I see in all the discussions are related to people using either different metaphors for the same name or leaving semantics ill-defined.

The *correct* working of ipairs,concat,sort,insert,etc. all depends on the initial premise.

As I proposed before, "my" arrays do not have holes, only unassigned or default values. 

So... what are those holes in "your" arrays? ;-)

-Frank.



On Jan 11, 2011, at 8:27 AM, steve donovan wrote:

> On Tue, Jan 11, 2011 at 6:04 PM, Frank Siebenlist
> <frank.siebenlist@gmail.com> wrote:
>> Could you please define your array semantics in more detail?
> 
> All that machinery is meant to stop holes getting into arrays. It's
> true that arrays-with-holes have their uses, e.g. the common idiom to
> handle nils in variable argument lists
> 
> function varargs(...)
>   local args = {n = select('#',...),...}
>   for i = 1,args.n do
>     ...
>  end
> end
> 
> Which is what (I think) you would regard as an array, no problem, and
> in fact this is now table.pack() in Lua 5.2.
> 
> But we cannot use ipairs() here, table.concat, table.sort, etc.  Holes
> still feel like bad news to me and they can be largely avoided.
> 
> steve d.
>