lua-users home
lua-l archive

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


On Sat, May 29, 2010 at 4:43 AM, Duncan Cross <duncan.cross@gmail.com> wrote:
> On Sat, May 29, 2010 at 8:27 AM, Jonathan Castello <twisolar@gmail.com> wrote:
>> I think it's slightly lamentable that "for i=1, 10, 100" is almost
>> identical to "for i in 1, 10, 100", but that's just me.
>
> You mean, just syntactically, you dislike that they are so similar? Or
> you think that they are actually semantically similar?
>
> for i =
>
> 1 is *not* a function. 10 is not an invariant
> I disagree, I do not think they are almost identical at all. 1
>

I'll admit I'm still thinking in terms of an __iter metamethod, in
which case "for i in x, y, z" would be equivalent to "for i in
metatable(x).__iter(x, y, z)" if an __iter exists. The __iter
metamethod itself would return the function, invariant, etc etc.

Maybe I got a little carried away in my enthusiasm for __iter at this
point, but you could have a default __iter behavior for numbers and
use things like "for i in 1, 10, 100" which becomes "for i in
metatable(1).__iter(1, 10, 100)". The semantics are effectively
identical when you get __iter involved.

~Jonathan