[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pairs(t, skey) and ipairs(t, skey)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 4 Oct 2013 16:31:20 +0200
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
>>
>
- References:
- pairs(t, skey) and ipairs(t, skey), Andrew Starks
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- Re: pairs(t, skey) and ipairs(t, skey), Tom N Harris
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- Re: pairs(t, skey) and ipairs(t, skey), Leo Razoumov
- Re: pairs(t, skey) and ipairs(t, skey), Roberto Ierusalimschy
- Re: pairs(t, skey) and ipairs(t, skey), Leo Razoumov
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- Re: pairs(t, skey) and ipairs(t, skey), Tim Hill
- Re: pairs(t, skey) and ipairs(t, skey), Luiz Henrique de Figueiredo
- RE: pairs(t, skey) and ipairs(t, skey), Schmidt, Phil