[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Regarding the name 'pairs'
- From: TNHarris <telliamed@...>
- Date: Mon, 14 Sep 2009 20:53:33 -0400
On Mon, 14 Sep 2009 10:34:36 -0400
Patrick Donnelly <batrick@batbytes.com> wrote:
>
> pairs and ipairs would still be useful with this __iter metamethod as
> tables have no __iter metamethod by default (naturally). We can also
> set the __iter metamethod of our metatables to next or (ipairs{}) to
> alleviate the need for calling pairs or ipairs manually.
>
This requires the object to be used as the state invariant for the
iterator function. This may not always be the case and would require
objects that need to use a different value for state to use a
non-standard iterator. The point of a metamethod is to increase use of
standard protocols. If the metamethod has the same form as "pairs" then
it works in all cases. I don't think the extra function call is too high
a price.
-- tom
telliamed@whoopdedo.org