lua-users home
lua-l archive

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


> Sorry to disappoint you, but this would not work for two reasons:
> 
> 1. Unpack ignores hash-part keys of the table.
> 2. More important, unpack(t1) == unpack(t2) compares only first
> elements of the tables. It is equivalent to t1[1] == t2[1]. There is
> no multi-argument equality operator, only assignment one.
> 
> Alexander.
Very good point for bearing in mind while in a rush..!

> Correction: #t1 may be 0 and in any case is not very useful.
> 
>     Enrico
Unless t1 = {1,2,3} and t2 = {['a'] = 1, ['b']...} or t2 = {1,2,3, ...}
Such as they'll be rejected immediatly. But it isn't so useful anyway  :)

> Try 'unpack({1,2}) == unpack({1,"banana"})'. That will return true as well,
> because only the first return value of unpack is evaluated on either side -
> it will be evaluating (1 == 1).
> 
> -Duncan

You are all very right. 
Thanks for pointing out the weaknesses of such approach.

(Feel free to ignore the rest of this message)

Now I wonder if there is a way in Lua scripts for comparing
table values so that loops can be minimized by using an
"internal" function, instead of looping as usual. Specially
if both tables are quite large and different just at the very end.

I am used to for loops comparing tables at i and n - i positions
at the same time, but it's probably prone to be slower in some
cases [...] And surely not useful for "dictionary" alike tables.

Greetings.

--
Mario