[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: '__iter', yet again!
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Wed, 16 Dec 2009 17:29:37 +0100
2009/12/16 John Hind <john.hind@zen.co.uk>:
> Argg! How can you put metatables and the colon operator in and then complain
> when people want to implement OO? I am not asking you to *enforce* OO for
> iterators, just to *support*
> it in the same way you support arithmetic and logical operations on tables
> used to implement Classes. Whether you want to express it in OO or in
> functional language (or ideally support both) having "generic for" implies
> the iteration property/ operation/ function /action at a purely conceptual
> level.
>
> What is the conceptual difference between "iteration" and, say, "arithmetic"
> which means that one deserves OO support (via metatables) and the other does
> not?
That's an important point. Now go meta for a second, and think about
all extension proposals. Nobody is saying that your proposal is not
good. Since it would be useful for at least one person (you), it is
good. But all proposals are good too. Should we integrate anything
that is proposed by anyone or should we put a limit somewhere ?
The fact is that there is a limit, some proposals are integrated, some
are not. In Lua 5.1.4, definable arithmetic is within the limit,
definable iteration ("iteration" being a that new concept that would
be implemented by iterators) is not. You have to show why it is worth
to move the limit.
So far I'm not convinced, but I don't decide. Just insist (or better,
provide a patch), and you might win the argument.
> Once the concept is admitted it ought to have the same flexibility of
> expression in different paradigms as other similar concepts.
>
> ** In passing, please note that this *does not* violate the (honoured
> mostly) principle that metatables should provide fallbacks not overrides.
> Currently if you execute:
>
> x = {}
> for k in x do end
>
> You get an error: "attempt to call a table value". So the proposed __iter
> would just be a fallback for this error in this context.
The operation that the VM tried, "call the value", already has a
fallback. The proposed __iter is a fallback, but for another
mechanism. Ok it's a fallback, but then it's not "just another
metamethod" that you are proposing.