lua-users home
lua-l archive

Re: Multiple values returned or vararg expression in numeric for loop

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


On 9/14/2012 9:59 AM, Egor Skriptunoff wrote:
On 9/14/12, Coda Highland <chighland@gmail.com> wrote:
If Lua patterns were to hold, the syntax would be
"for <variable> = <exprlist> do"
rather than
"for <variable> = <expr>, <expr>[, <expr>] do".
/s/ Adam
Why Lua uses the latter syntax, but not the former?
Because. I couldn't tell you. There's probably a reason for it.
In fact, numeric "for" loop just accepts a usual list of values.
No, it does //not//. It may look like a list of values, but as others have told you, it really isn't. And yes, this is confusing. Again, if numeric "for" really "just accepts a usual list of values", the format would have to be
"for <variable> = <exprlist> do"
while it is
"for <variable> = <expr>, <expr>[, <expr>] do"
The syntax may as well have been
"for <variable> = <expr> $ <expr> [! <expr>] do"
without structurally changing the symantics.
What is the reason for this syntax to be unlike it expected to be?
You're reversing the problem.

AltStyle によって変換されたページ (->オリジナル) /