[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: '__iter', yet again!
- From: Geoff Leyland <geoff_leyland@...>
- Date: Thu, 17 Dec 2009 07:26:14 +1300
On 17/12/2009, at 3:32 AM, Francesco Abbate wrote:
> But there is an error in your arguments because the '__iter'
> metamethods does not add a new concept to the language. The feature is
> already there and is the metamethods mechanism itself. We are just
> talking about adding a new metamethod category to handle iterations
> over objects.
> When you write:
> obj[key] = value
> and you call secretly the '__newindex' metamethods, this is *exactly
> the same* logic of calling __iter in the construct:
> for val in obj do
Isn't one difference between the two that without metamethods there's no way you could add special functionality to 'obj[val]' or 'obj1 + obj2', whereas it's trivial to write your own versions of pairs and ipairs that respect your own __iter metamethod?