lua-users home
lua-l archive

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


On Thu, Dec 30, 2010 at 07:25:39PM +0200, Greg Falcon wrote:
> On Thu, Dec 30, 2010 at 11:46 AM, Dirk Laurie <dpl@sun.ac.za> wrote:
> > Standard table functions don't destroy the pristine property
> > and updating (b) is trivial.
> 
> This is incorrect.  For array t={1,2,3}, both
>   table.insert(t, 1, nil)
> and
>   table.insert(t, -42, 'x')
> destroy your "pristine" property.
> 
You shock me.

The reference manual says:

    Most functions in the table library assume that the table 
    represents an array or a list.
...
and under 'insert',
    shifting up other elements to open space, if necessary. 

In both your examples, I can't see why it is necessary to shift 
up the other elements, since there should be no distinction 
between t[1]=nil and t[1] absent.

Thus, these examples expose what one could describe charitably 
as unintended behaviour of table.insert.

Even so, in both cases, the loss of pristineness can be diagnosed
in O(1) time, so this detail does not destroy my argument.

Dirk