[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why can't I do for...in on a table?
- From: Chris Marrin <chris@...>
- Date: Mon, 12 Sep 2005 15:06:47 -0700
Luiz Henrique de Figueiredo wrote:
In fact, it might have been better to define the iterator syntax like this:
for p = next,t,nil do ... end
which looks like the numeric for loop. If the first expression is a
number, you would use numeric iteration. If it is a function, you would
use iterators.
The whole point of having two different forms for "for" is to be able to
generate good code in both cases, specially in the numeric "for". If the
syntax was the same, the checks would be needed at run time and it wouldn't
be possible to have special VM instructions for each "for" variant.
True. A separate statement would be better. I guess I was trying to
speak to the "lua has a tiny little BNF" gods :-)
--
chris marrin ,""$,
chris@marrin.com b` $ ,,.
mP b' , 1$'
,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :$1
b$` ,$: :,`` |$$ ,` $$` ,|` ,$$,,`"$$ .` :$|
b$| _m$`,:` :$1 ,` ,$Pm|` ` :$$,..;"' |$:
P$b, _;b$$b$1" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'