lua-users home
lua-l archive

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


2013/10/4 Schmidt, Phil <PSchmidt@watlow.com>:
> "A sequence in Lua has no holes and # returns the number of elements in a sequence."

The responsibility for knowing whether something is a sequence
rests on the programmer. The table library is sequence-in,
sequence-out but elsewhere Lua does not maintainn the table
property automatically.

> Does not the example below contradict the statement above? If not, then why not?

Because at the poiny marked `^^^^` `a` has acquired a hole and
is therefore not a sequence, so the result of applying `#` to it is
no longer defined.

>
>
> Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
>> a={'a','b','c','d'}
>> print(#a)
> 4
>> for k,v in ipairs(a) do print(k,v) end
> 1       a
> 2       b
> 3       c
> 4       d
>> a[3]=nil
^^^^
>> print(#a)
> 4
>> for k,v in ipairs(a) do print(k,v) end
> 1       a
> 2       b
>>
>