lua-users home
lua-l archive

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

> If anything this discussion shows that no policy lua sets will be
> satisfactory for every use case. As I've said in the past, I would rather
> see lua adopt its philosophy of allowing the programmer set the policy:
> don't set 'n', return the length in the second return.

I do not think that table.pack returning a .n field is a policy set
by Lua. In particular, no function assumes the existence of such a
field. This is just particular to table.pack.

(The old implementation of varargs used such a field and that was never
a problem.  The problem was the use of that field by remove/insert and
similar functions. That set a policy.)

Previous experience with string.gsub shows that, sometimes, it is not
such a good idea for a function to return two values; it often leads
to confusion when people forget about the second return. The message
that started this discussion hints that table.pack with two returns
would be in the same category of string.gsub.

-- Roberto