Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Like a well trained Pavlov dog[1], reading the title brought "Lua table"[2] to my mind, the most flexible data structure I have worked with, by far.

[1] https://en.wikipedia.org/wiki/Classical_conditioning

[2] http://www.lua.org/pil/2.5.html



> reading the title brought "Lua table"[2] to my mind, the most flexible data structure I have worked with, by far.

Which is not necessarily a good thing. PHP's array and JS's Object are essentially the same thing.


Lua tables accept arbitrary objects as keys, and make a difference between `foo[1]` and `foo["1"]`.

Plus all the metatables goodies: weak key and/or value references, prototype inheritance, ...


They even mark the difference to the degree that foo[1] is stored in a special "array part" of the table, while foo["1"] ends up in the hash part. Predictably, the array part uses less memory.


> Lua tables accept arbitrary objects as keys, and make a difference between `foo[1]` and `foo["1"]`.

That sounds... completely normal? Python dictionaries will do that too. So will Java HashMaps.


That comment was responding to a comment about PHP and JS, both of which do not make such a distinction.


There is another subtlety that values associated with integer keys are stored as an array. dicts and HashMaps don't do this.


And not even all integer keys! Lua will efficiently handle sparse arrays using tables.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: