lua-users home
lua-l archive

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


I believe the point is not whether the current semantics are
consistent with the syntax as defined in the manual but whether it
might be more natural to change the syntax so as to align it with what
one might naturally expect to work.  In this respect Hisham does have
a valid point: since the syntax of the for loop is:

for v = a, b, c do .. end

or

for v = f() do ... end

if you use a function call one would expect it to work like:

v = f()

in which case the returned values would be adjusted to a single value
as happens for the for statement.  You can therefore treat the part of
the for statement that looks like an assignment as an actual
assignment in terms of semantics.  From this point of view not
adjusting the values returned by f would be then inconsistent thing to
do.

On Fri, Sep 14, 2012 at 11:45 AM, Martijn van Buul
<martijn.van.buul@ellips.nl> wrote:
> 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.
>
>
>