[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: '__iter', yet again!
- From: Mark Hamburg <mark@...>
- Date: Wed, 16 Dec 2009 14:40:48 -0800
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Mark Hamburg
Sent: 16 December 2009 21:21
To: Lua list
Subject: Re: '__iter', yet again!
> The argument against:
>
> It changes the semantics of the generic for loop from taking an iterator to
> taking an iterator or an iterator factory.
>
> The factory is distinctly one step removed from an iterator and hence is not
> analogous to a table pretending to be a function (__call) or a table
> pretending to be a number (__add).
On Dec 16, 2009, at 1:44 PM, John Hind wrote:
> No, it would be a table pretending to be a collection (or, we might say, a
> table pretending to be a table!).
>
> The simplest implementation would be:
>
> setmetatable(obj, {__iter = pairs;})
>
> So whatever you want to call 'pairs', (factory, generator, whatever) the
> metamethod is called the same! (But I accept that maybe '__iter' is the
> wrong key for it.)
That, however, is a semantic change. The generic for doesn't take collections. It takes an iterator triple. Note in particular that for doesn't take pairs. pairs takes a table and returns an iterator triple for the table.
Mark
- References:
- Re: '__iter', yet again!, Jerome Vuarand
- Re: '__iter', yet again!, Luiz Henrique de Figueiredo
- Re: '__iter', yet again!, steve donovan
- Re: '__iter', yet again!, Javier Guerra
- Re: '__iter', yet again!, Mark Hamburg
- Re: '__iter', yet again!, Cosmin Apreutesei
- Re: '__iter', yet again!, Petite Abeille
- Re: '__iter', yet again!, Cosmin Apreutesei
- Re: '__iter', yet again!, Petite Abeille
- Re: '__iter', yet again!, Mark Hamburg
- RE: '__iter', yet again!, John Hind