[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Regarding the name 'pairs'
- From: "John Hind" <john.hind@...>
- Date: Fri, 11 Sep 2009 14:09:19 +0100
Thanks for the support on "__pairs" and "__ipairs".
But is your other point really true? With "__call", the parser resolves a
call of the function in the metatable under the index "__call" passing the
iterable object. With the method approach, the parser resolves a call of the
function in the metatable under the index of the method name, again passing
the iterable object. In both cases, the function call must return the same
values the pairs or ipairs functions would return, i.e. a function to do the
iteration, the object to be iterated and nil.
It seems to me that the only difference is the "syntactic sugar": the method
call is transformed by a pre-processor before being parsed while the call
via the metamethod is parsed directly. The pre-processor and the parser seem
to be using different rules to recognise a call. Of course I cannot test
this, since once the "syntactic sugar" is expanded out, there is a parameter
and so you need the parenthesis!
> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-
> bounces@bazar2.conectiva.com.br] On Behalf Of steve donovan
> Sent: 11 September 2009 11:13
> To: Lua list
> Subject: Re: Regarding the name 'pairs'
>
> Yes, because myobject is callable. But myobject:iter() _returns_ a
> callable, usually a closure that contains iterator state.
>
> That's the difference.
>
> PS, I do agree that __ipairs and __pairs seems silly.
>
> steve d.