[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Why does numeric for loop not accept an explist?
- From: "Peter Cawley" <lua@...>
- Date: Mon, 31 Dec 2007 14:06:31 +0000
Generic for loops can use either a function call or an explicit
argument list, like so:
for key, val in pairs(t) do
print(key, val)
end
for key, val in next, t do
print(key, val)
end
However, numeric for loops are restricted to an explicit argument
list, so the first example won't compile:
function indicies(t) return 1, #t end
for key = indicies(t) do
print(key, t[key])
end
for key = 1, #t do
print(key, t[key])
end
This is exactly what the complete syntax specifies:
for Name `=´ exp `,´ exp [`,´ exp] do block end |
for namelist in explist do block end |
The complete syntax does not give the reason for this, so what is the
rationale behind this decision?