lua-users home
lua-l archive

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


The language _has_ lists, lists are tables in which all positive
integers are from 1 to k. Lists are tables for which # is bijiective.
Lists are the only tables insert and remove should be used upon.

I did not say to change the default ltable.c implementation, but to
change the default way table.insert() and table.remove() work. As
argued even from the defendands they are used to be on Lists only. So
whats the problem of those by default requiring a table which has
"List" as metatable, which ensures a list is a list. Pro's could
easily remove this checks by say table.insert = table.insert_raw;
table.remove = table.remove_raw;

Additionally the more I think about lists and nil values, I see all
the problems arise of lists not storing their length as explicit
variable.

If there is a table a[1] = 'a',   a[4] = 'd'  .. to be considered a
list it is |'a', nil, nil, 'c'|
So in my opinion if one removes 'c' by table.remove(a, 4); it should
be |'a', nil, nil| ... this would all be much less a problem if "n"
would be a seperate variable for tables considered to be lists (and
thus insert and remove should work on them)

On Tue, Jan 11, 2011 at 2:19 PM, David Kastrup <dak@gnu.org> wrote:
> Axel Kittenberger <axkibe@gmail.com> writes:
>
>> Indeed, for my taste and coder-newbie-friendliness, it would be nice
>> if paranoid lists would be default
>
> Are we still talking about the language or about the mailing lists?
>
> The language does not _have_ lists.  It has tables.  You can use them
> for emulating various other data structures with their own invariants.
> Violate the respective invariants, and the emulation suffers.  If you
> desperately want to make it impossible to violate the invariants, use
> appropriate metatables for each emulation prohibiting the violation of
> the respective invariant.
>
> But there is little point in reducing the efficiency and versatility of
> the _only_ underlying data structure Lua has.
>
> --
> David Kastrup
>
>
>