|
John Hind wrote:
And the __pairs and __ipairs metamethods are unnecessary since anyone who wants to redefine pairs and/or ipairs (including to implement metamethods) can just replace the functions with their own implementations (in Lua). I still think the approach implemented in my "Self-iterating Tables" PowerPatch is a much more useful innovation.
Reimplementing pairs/ipairs/etc doesn't scale: it starts breaking in "interesting" ways as soon as multiple people do it.
Implementing them in terms of (optional) metamethods makes them into "virtual operators". Python does the same. C++ does something similar with argument dependent lookup.
It's generally a sign of good language design (IMO) when a language makes things so pervasively extensible.
|