lua-users home
lua-l archive

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


I agree entirely ...

I guess the reason why the method call does not work with an empty
parenthesis is that it is not parsed directly but translated to
list.iter(list) before parsing and the textual translation requires the
empty parenthesis. Pity - if it is syntactically unambiguous in one case it
should be in the other too - as you say, both are "really" just function
calls.

> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-
> bounces@bazar2.conectiva.com.br] On Behalf Of steve donovan
> Sent: 09 September 2009 13:05
> To: Lua list
> Subject: Re: Regarding the name 'pairs'
> 
> On Wed, Sep 9, 2009 at 1:44 PM, John Hind<john.hind@zen.co.uk> wrote:
> > 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?
> 
> Well, e.g. the style I tend to use these days is
> 
> for val in list:iter() do .. end
> 
> Where iter is a method which _returns_ a function, which is what the
> for statement is expecting. (It will call it repeatedly until it
> returns nil)
> 
> If list had a __call metamethod, then it is callable, and the for
> statement just goes with that.
> 
> And that's it, as you've discovered: __call is a hack here because
> what we're really trying to express the concept of 'iterable', not
> 'callable', which are quite distinct. Hence __iter ;)
> 
> steve d.