lua-users home
lua-l archive

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


On Mon, 24 May 2010, Jonathan Castello wrote:

> > 2) breaks the current iterator protocol
> 
> Hrm, I tried to make sure it didn't do that. What about it does this?
> It takes the first item on the right and first tries its __iter, then
> tries to call it. All current uses I can reasonably think of should
> still work unchanged.

Rereading the proposal I'm no longer sure how it's supposed to work 
exactly.  Any chance of presenting it in pseudocode at the level of 
http://www.lua.org/manual/5.1/manual.html#2.4.5 "A for statement ... 
is equivalent to the code ..." ?

Regarding speed of numeric for and setup overhead of your "for i in 
100,1,1 do" style loop, you asked if the compiler couldn't optimise 
the latter into the equivalent of a numeric for.  The answer to that 
is probably "no, it can't (without significant effort)" because the 
user can change the metatable of numbers whenever they please to make 
the loop go up, down or sideways.

Cheers,

Joonas