lua-users home
lua-l archive

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



On Jul 6, 2013 8:32 PM, "Sean Conner" <sean@conman.org> wrote:

> It was thus said that the Great Jay Carlson once stated:
> > Let's take the following code, applied to an array-like table:
> >
> >   i = #t
> >   t[i] = nil
> >
> > This could mean three things:
> > [...]
> > Note that metatables can help for a fixed length array; __len can always
> > return (say) 256, always producing behavior 3. But there can't be a
> > shrinkable array.
> >
> > So, for total overkill, I introduce new syntax to make intent clear:
> >
> >   i = #t
> >   delete t[i]
>
>   That already exists in Lua:  table.remove().  It even allows one to remove
> an arbitrary entry anywhere in the array.

Yes. However, the behavior I propose for t[#t]=nil does not exist in the language or libraries: there isn't a way of keeping a nil at the end of an array without a custom metatable, and there is no way for that metatable to distinguish between delete and assign without an ad-hoc protocol.

Jay