lua-users home
lua-l archive

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


On Fri, 29 Jan 2010 18:23:24 +0800
"Alex Davies" <alex.mania@iinet.net.au> wrote:

> > -4- If the above is true, then why isn't this the common way, since it 
> > seems to have only advantages:  
> I cannot imagine why any language would do it any other way.

> a="1" ; b="1"
> t = {}
> t[a] = "foo"
> print (t[a],t[b])
foo	foo

-- case table keys
> c = {1} ; d = {1}
> t[c] = "foo"
> print (t[c],t[d])
foo	nil

Some people think associative array keys should return the same item if they are equal (in value). That's what python folks think, for sure. This is probably true, I guess, at least in most common cases. But in practice I never met any case where Lua's behaviour raises an issue --yet. Also, this is consistent with Lua's default equality for table (but *this* is a problem for me: I need a custom table.equality func based on value).
A pointer to this topic in the Java world (thank to Kent Johnson, from python tutor list):
http://www.javaworld.com/javaqa/2002-06/01-qa-0621-hashtable.html 

Denis
________________________________

la vita e estrany

http://spir.wikidot.com/