lua-users home
lua-l archive

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

On Tue, Jul 1, 2008 at 4:06 AM, Eric Tetz <> wrote:
> I just read the link Petite provided, and it's 100% apropos. Go read it. :)

Thanks a lot everyone who replied.  Let us see what the manual really says:

(1) Definition of table.concat

"table.concat (table [, sep [, i [, j]]])
Given an array where all elements are strings or numbers, returns
table[i]..sep..table[i+1] ··· sep..table[j].
The default value for sep is the empty string, the default for i is 1,
and the default for j is the length of the table.
If i is greater than j, returns the empty string."

NOTE: the definition above never explicitly addresses the issue of
arrays with holes.
Is a hole an element with nil as a value (nil is nither string nor number)??
See below.

(2) Arrays with holes are discussed here

"The type table implements associative arrays, that is, arrays that
can be indexed
not only with numbers, but with any value (except nil). Tables can be
that is, they can contain values of all types (except nil).
Like indices, the value of a table field can be of any type (except nil). "

NOTE: the manual explicitly says that nil cannot be a value in an
array or table (nil also cannot be a valid key).
Direct interpretation of the paragraph above: "t[2]=nil means that
array t does not contain an element t[2]"
It is different from "t[2] exists and has a value of nil".

(3) another discussion of arrays with holes

"For a regular array, with non-nil values from 1 to a given n, its
length is exactly that n,
the index of its last value. If the array has "holes" (that is, nil
values between other non-nil values),
then #t may be any of the indices that directly precedes a nil value
(that is, it may consider any such nil value as the end of the array)."

NOTE: according to (3) arrays can have elements with nil as a value,
contradiction with (2) "the value of a table field can be of any type
(except nil)."

My head is spinning:-)
I think the manual should bee more specific of what a t[key]= nil really means
(A) t[key] element exists and is set to nil
(B) t[key] element is absent from the table/array and has not material value