lua-users home
lua-l archive

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


On 5 September 2013 17:25, Tim Hill <drtimhill@gmail.com> wrote:
>
> On Sep 5, 2013, at 12:06 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>
> Really? I was under the impression it wanted an expression list
> (of which it uses only the first three items). In which case I don't
> see the ambiguity between __call and __in (or whatever it could
> be called).
>
>
> At the syntax level (dare I call it the language lawyer level?)
> you are right, of course. But what Lua does to the first of those
> expressions is to try to call it.
>
> $ lua
> Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
>
> for k in 3 do print(k) end
>
> stdin:1: attempt to call a number value
>
>
> Urgh .. what a mess. That's certainly not what the Lua Ref manual says, and
> is not consistent with other places that expression lists are used.
>
> --Tim
>

The manual says that the results of the expression list "...are an
iterator function, a state, and an initial value for the first
iterator variable."[1][2] The "equivalent" code shows `f` (an iterator
function, the first value from the expression list) being called with
`s` and `var` (the state and the first iterator variable, the second
and third values from the expression list) as arguments to produce the
new values for the loop variables.

[1] http://www.lua.org/manual/5.1/manual.html#2.4.5
[2] http://www.lua.org/manual/5.2/manual.html#3.3.5