lua-users home
lua-l archive

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


Wow, that's just way too much for the user...
Almost too much of a wart for a regular programmer.

I can understand it autoincrementing the index,
but that doesn't exactly mean changing the index
in the for loop is erroneous...just odd... right?

--- In lua-l@y..., RLake@o... wrote:
> 
> > Although 'local' does make a nice difference with while,
> > it doesn't really with this for example. Even with the
> > x=i, it is pretty much the same speed as without, and
> > still plenty faster than while...
> 
> > However, I would like to know why... what does it mean?
> > And what is the rationale behind it especially when it
> > makes things cryptic for the non-programmer users...
> 
> Maybe it is cryptic. The simple explanation is that a "local" 
variable
> only exists in the piece of program it occurs in. Since Lua knows 
where all
> the uses of the local variable are, it can find them much more 
easily.
> 
> For example, the "i" in the for loop is local to the for loop; it 
doesn't
> exist
> outside the for loop. This is what makes for loops so fast (or one 
of the
> things
> that makes them so fast, anyway). So changing that would make for 
loops
> slower.
> 
> By the way, i = F(i) is not allowed. You cannot change the value of 
the
> index of
> a for loop inside the for loop. I suppose it works for you because F
(i)
> returns i.
> 
> >  local x=-1
> >  for i=1,10000000 do
> >    i = F(i)
> >    x = i
> >  end
> 
> > That's too much for users I think, is there any solutions
> > that makes sense, which is not twice as slow like 'while' ?
> 
> Not really. Sorry.