[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: '__iter', yet again!**
**From**: Roberto Ierusalimschy <roberto@...>
**Date**: Wed, 16 Dec 2009 14:32:08 -0200

> What is the conceptual difference between "iteration" and, say, "arithmetic"
> which means that one deserves OO support (via metatables) and the other does
> not?
First, I do not think that metamethods for arithmetic operations is
any kind of "OO support". (I cannot think about algebraic values as
"objects".)
Second, maybe there is no conceptual difference, but there are
pragmatic differences. An iteration is something much heavier than an
arithmetic operation syntatically (and usually semantically too). So,
adding an explicit iteration function seems lighter than using
explicit functions for arithmetic. Also, we have several arithmetic
operators for different operations, but only one generic for that
should support several kinds of iterations.
I do not think it is anathema an __iter metamethod, but I am not sure it
pays off. (Among other thinks, it would not allow trivial things like
the "for k,v in t" of old versions, because tables do not have a common
metatable.)
-- Roberto