lua-users home
lua-l archive

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


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