lua-users home
lua-l archive

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

On Wed, Sep 9, 2009 at 1:44 PM, John Hind<> 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.