lua-users home
lua-l archive

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


On Wed, Oct 2, 2013 at 1:55 PM, Paul K <paulclinger@yahoo.com> wrote:
> This
> shows that 1,2,3 are actually stored in the array part and are always
> iterated over first. #t is 3 in both cases.

I ran your code and I follow you. I believe what you are saying is that:

t={ [3]=3, [2]=2,[1]=1}

...is not really a sequence, as far as CSCI might be concerned. Or to
put it another way:

t = {}

t[3] = "foo"
t[1] = "bar"
t[2] = "baz"

...isn't "not a sequence" for the first two index assignments and then
suddenly pops into "sequence" in the third index assignment. It
started life as "not a sequence" and continued to be not a sequence.

The most important point to make is that "#" is not acting on a
sequence. It's counting the sequential numeric keys in a table,
starting from `1`.

So the "array" part of a table provides an optimization. I wonder how
Lua could know where the break in the sequence was, without looping
through every key in the hash portion?

If it does this, then the answer to the question of, "Are there more
integer keys after or before #?" is "out there", but not bubbled up.
If it's using some further optimization (that I actually am trying to
imagine, but cannot), then maybe this answer is further out there than
needed.

Then again, maybe that answer isn't even good enough for the problem
that people are attempting to solve...

-Andrew