[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lists with nil play nice for Lua 5.2
- From: David Given <dg@...>
- Date: Sat, 28 Jul 2007 22:41:43 +0100
-----BEGIN PGP SIGNED MESSAGE-----
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
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?
┌── ｄｇ＠ｃｏｗｌａｒｋ．ｃｏｍ ─── 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
-----END PGP SIGNATURE-----