[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lists with nil play nice for Lua 5.2
- From: Asko Kauppi <askok@...>
- Date: Sun, 29 Jul 2007 22:16:41 +0300
I agree with John about the annoyance of this non-intuitive nil
handling. And I do my set of tricks around it, as John pointed many
of us do...
As a solution, how about just making #tbl etc. _fail_ if they are
applied on a table that somehow is known to have holes in it. Then
again, if that can be efficiently found out it wouldn't take much
more to fallback to a less efficient hopping-over-holes algorithm for
those failing cases. The annoyance is the unexpected behaviour, this
certainly is one of Lua's "traps" (which every language has some).
Fixing the issue with #, unpack() etc. would not in my opinion hurt
the general use of tables, in any way. It might cause these operators
to run a bit slower, though (which is the real problem as far as I
David Given kirjoitti 29.7.2007 kello 0:41:
-----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
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
collection of key->value pairs. What you're referring to as a list
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
*unset* item in the dictionary is considered to have a value of
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,
contradicted yourself: the keys are no longer contiguous because
one item is
unset. Since all the array operators are defined to *only* work on
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
problem is that the abstraction you've based your code design
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?
┌── ｄｇ＠ｃｏｗｌａｒｋ．ｃｏｍ ───
│ "There does not now, nor will there ever, exist a programming
│ which it is the least bit hard to write bad programs." ---
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----