lua-users home
lua-l archive

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


On Tue, 19 Aug 2014 09:06:40 -0300
Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:

> I really do not think that ipairs + __ipairs is a good generic iterator
> interface. That was never the intention when we created __ipairs. Among
> other problems, it forces an object to have only one "true" iterator; it
> is too "object" centric.

Yet another thought occurred to me:

If __ipairs would be too object centric (since an object can have more
than one way to iterate it), then wouldn't __pairs be also too object
centric as well? (since there are multiple ways to gather key-value
pairs from an object)

The same could hold for __call (since there are multiple ways of
function-like invocation) and __index (since there are multiple
possible ways of "accessing" an object through a key).


To give an example for __index:

record["phone"]

versus

record:by_key("phone")
record:by_key_without_cache("phone")
record:by_column_index(7)
record:by_description("Phone number")


Or another example for __call:

sql_connection("SELECT * FROM employee")

versus

sql_connection.query("SELECT * FROM employee")
sql_connection.async_query("SELECT * FROM employee")


Regards
Jan