[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Definition of table.insert
- From: Frank Siebenlist <frank.siebenlist@...>
- Date: Tue, 11 Jan 2011 08:42:53 -0800
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.
>
- References:
- Re: Definition of table.insert, Henning Diedrich
- Re: Definition of table.insert, Dirk Laurie
- Re: Definition of table.insert, Axel Kittenberger
- Re: Definition of table.insert, David Kastrup
- Re: Definition of table.insert, Henning Diedrich
- Re: Definition of table.insert, Dirk Laurie
- Re: Definition of table.insert, Axel Kittenberger
- Re: Definition of table.insert, steve donovan
- Re: Definition of table.insert, Frank Siebenlist
- Re: Definition of table.insert, steve donovan