lua-users home
lua-l archive

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


Jerome Vuarand wrote:

So far the only real argument in favor of truncation on
that discussion is that it's an implementation limitation.
All other arguments are either irrelevant (a matter of
personnal preference) or applicable to the last argument
too.

Forgive me for quoting myself, but in Kurt's and my book
(page 80) I wrote:

This rule (adjust every expression except the last to one
value) may seem more complicated than necessary, but there
is good reasoning behind it.  If every expression in a
value list were adjusted to one value, there would need to
be a special way to override this, which would make the
ability of Lua functions to return multiple values harder
to use.  If no expressions in a value list were adjusted
to one value, then any function returning less or more
than one value would throw off the positioning of
everything that came after it in the value list.

Take the following statement:

 Foo(Bar(), Baz(), Quux())

In that statement, Quux() returning more than one value when
you think it returns one is only a problem if Foo() takes
more arguments than you think it does.  In a stipulated Lua
that doesn't adjust return values, Bar() and Baz() returning
more or less than one value when you think they return one
would always be a problem, because it would throw off the
alignment of the remaining arguments.  (Similar reasoning
applies to multiple assignment or table constructors.)

I think Lua's actual behavior is a good middle road between
making multiple returns hard to use and making them a
too-fertile source of bugs.

--
Aaron
http://arundelo.com/