lua-users home
lua-l archive

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


2009/12/16 Jerome Vuarand <jerome.vuarand@gmail.com>:
> 2009/12/16 John Hind <john.hind@zen.co.uk>:
>> I really cannot see why this solution is resisted – it is fully backward
>> compatible and syntactically uncomplicated. The context of the explist is
>> easily distinguishable being bracketed by the reserved words ‘in’ and ‘do’.
>
> The beauty of the language, is that it has very few concepts, used in
> many places. Rather than having a specific mechanism to iterate over
> objects, the for loop use the mechanisms of multiple return values and
> first class functions. The resistance comes from the fact that you
> want to make Lua more complicated, just to save an explicit method
> call. And that's assuming that the implicit __iter is better syntax
> than an explicit method, which is arguable (e.g. I would disagree with
> you). And concise and cryptic syntax overriding isn't even part of OO,
> it's just often bundled with it.

I agree with you that having few simple concepts to describe the
language is a very important benefit. This is also the reason why,
personally, I like the C programming language: a few pervasive
concepts and everything else is left to the programmer.

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

Namely, a language construct that is overloaded with object behaviour
by using metamethods.

For the other side I think that the __call metamethod is weird because
the calling of a function is such a fundamental construct that
overloading it can be confusing when you read the code. For the other
side is can always choose to not overload __call if you prefer so.

Francesco