lua-users home
lua-l archive

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

> -----Original Message-----
> From: [mailto:lua-
>] On Behalf Of Adrian Sietsma
> Sent: 10 June 2009 16:20
> To: Lua list
> Subject: Re: Next Version of Lua? (__iter metamethod)
> I often have multi-use tables, such that t[id] = t[n] = object.
> I can then lookup objects by id, or iterate them with ipairs.
> In this case, how would your code 'contextually select' the iterator ?

So why would you want to use "pairs" in this case? If your table meets the
requirements for "ipairs" and you do not care what order the elements are
returned in, what is wrong with "ipairs"? Either "ipairs" works and is
sufficient, or it does not, in which case you have to use "pairs". In any
case, metamethods only impact if you choose to use them, so nothing breaks
your code. Why would you want to use the proposed "__pairs" or "__ipairs"

> > Apart from this consideration of principle, it is using two
> metamethods to
> > do a half-assed job that could be properly done with just one!
> Is the solution half-assed, or your understanding of the problem ?

Always possible, as of course may be your understanding! Actually I do not
think there is a problem here - just an opportunity for improvement, or for
taking a backward step.