lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John Belmonte wrote:
[...]
> Clearly they are not sparse as constructed.  Stepping back, a list is
> generally defined a series of values.  Lua nil is a first class value--
> an incredibly useful one-- which should not render lists practically
> useless.

The thing is, though, a Lua table is not a list. A table is a dictionary, a
collection of key->value pairs. What you're referring to as a list is merely
an Lua array: a table with a contiguous set of integer keys starting at 1.

The reason why the documentation refers to nil values as 'holes' is because an
*unset* item in the dictionary is considered to have a value of nil. You
remove a mapping by setting its value to nil. So if you try to define a table
with a contiguous set of integer keys, etc, with one value as nil, then you've
contradicted yourself: the keys are no longer contiguous because one item is
unset. Since all the array operators are defined to *only* work on tables that
are valid arrays, then of course they'll fail.

I realise it's not an awful lot of help to you, but I think the key to your
problem is that the abstraction you've based your code design around, the
list, is not the same one that Lua is providing. So of course you're going to
run into problems.

What is it exactly you're trying to achieve?

- --
┌── dg@cowlark.com ─── http://www.cowlark.com ───────────────────
│
│ "There does not now, nor will there ever, exist a programming language in
│ which it is the least bit hard to write bad programs." --- Flon's Axiom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGq7gXf9E0noFvlzgRAhvVAJ9aQhwbJz54zF9h9oqzhhyzAB3SswCfXM7E
BaEYRG2e0vLxJORJX2Ix4qM=
=lS16
-----END PGP SIGNATURE-----