[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Regarding the name 'pairs'
- From: "John Hind" <john.hind@...>
- Date: Wed, 9 Sep 2009 12:44:01 +0100
Yes indeed - I contributed to that thread! The __call trick is one I have
used many times and it is fine until you do a delegate class and want both a
function call metamethod and a custom iterator for the same class!
I am puzzled as to why it is OK to drop the empty parenthesis when doing a
"pseudo" function call but not when doing a "real" method call?
The difficulties (but not showstoppers) of the __iter approach have been
addressed in the earlier thread, but the survival of the (IMHO pointless)
"__pairs" and "__ipairs" approach has not. These are just bloat and buy us
next to nothing: the alternatives available to anyone who wants these are
even easier than those available to the "__iter" camp!
> -----Original Message-----
> From: firstname.lastname@example.org [mailto:lua-
> email@example.com] On Behalf Of Luiz Henrique de
> Sent: 09 September 2009 12:03
> To: Lua list
> Subject: Re: Regarding the name 'pairs'
> > I would prefer a single __iter metamethod with deeper language
> > so we can write:
> > for v in myobject do print(v) end
> You can do that already:
> > for v in myobject:myiterator do print(v) end
> This is a syntax error. These would work:
> for v in myobject:myiterator() do print(v) end
> for v in myobject.myiterator do print(v) end