[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pairs(t, skey) and ipairs(t, skey)
- From: Tim Hill <drtimhill@...>
- Date: Wed, 2 Oct 2013 14:41:22 -0700
On Oct 2, 2013, at 2:29 PM, Sean Conner <sean@conman.org> wrote:
>
> Given:
>
> t_seq = {}
> for i = 1 , 99 do
> t_seq[i] = nil
> end
> t_seq[100] = "Boom"
>
> t_hole = {}
> t_hole[100] = "Boom"
>
> What should the following print?
>
> print(#t_seq)
> print(#t_hole)
>
> Now, given that both tables have indicies 1 through 99 as nil, and 100 as
> "Boom", should the two be treated differently? Why? They are "equal" to
> each other:
>
> for i = 1 , 100 do
> if t_seq[i] ~= t_hole[i] then
> print("they are different")
> end
> end
>
> I contend that this is just as confusing as the current behavior.
>
> How about "The # operator returns the highest integer key of the table"?
>
> -spc
>
They both print nil, because neither of them are sequences as per the definition .. I didn't put all the details in the pseudo-code to avoid confusion, but clearly putting "nil" in an out-of-sequence location is simply ignored (since by definition at that point you are merely deleted a nonexistent slot, which is a no-op).
They are equal, but not sequences .. this is also true according to the existing definition, so nothing has changed.
--Tim
- References:
- Re: pairs(t, skey) and ipairs(t, skey), Dirk Laurie
- Re: pairs(t, skey) and ipairs(t, skey), Paul K
- 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), Tim Hill
- 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), Tim Hill
- Re: pairs(t, skey) and ipairs(t, skey), Sean Conner