[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Regarding the name 'pairs'
- From: steve donovan <steve.j.donovan@...>
- Date: Wed, 9 Sep 2009 14:04:38 +0200
On Wed, Sep 9, 2009 at 1:44 PM, John Hind<email@example.com> 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
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 ;)