lua-users home
lua-l archive

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


Ok, thank you! So in a list of expr a vararg is evaluated to the first element of the vararg unless last in the list. 

May I ask why this is?

Basically I wanted a double recursive function return an appended list of expressions, but I ended up storing the expr in tables instead and explicitly appending them. 

Thanks,
Fredrik Widlnud
________________________________________
Från: lua-l-bounces@lists.lua.org [lua-l-bounces@lists.lua.org] för Patrick Donnelly [batrick@batbytes.com]
Skickat: den 15 juni 2011 15:03
Till: Lua mailing list
Ämne: Re: pack/unpack

On Wed, Jun 15, 2011 at 8:57 AM, Fredrik Widlund
<fredrik.widlund@qbrick.com> wrote:
> Hi,
>
> Could someone explain if the following is by design:
> Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
>> a={1,2,3}
>> b={4,5,6}
>> c={unpack(a), unpack(b)}
>> print(table.concat(c, ","))
> 1,4,5,6
>
> It seems the second unpack starts "writing" its members to position i+1 and thus overwrites the members of the first unpack? Is this really correct behaviour?

See the manual [1].

"If a vararg expression is used inside another expression or in the
middle of a list of expressions, then its return list is adjusted to
one element. If the expression is used as the last element of a list
of expressions, then no adjustment is made (unless that last
expression is enclosed in parentheses)."

[1] http://www.lua.org/work/doc/manual.html#3.4.9

--
- Patrick Donnelly