lua-users home
lua-l archive

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


chris <csrl <at> gmx.com> writes:
> Because the length operator is not stable, it does not make sense to me that
> this would be the default in table.unpack.  Rather, it seems more interesting 
> to me to have table.unpack look for an 'n' index and use it.  Or make the index
> range to unpack required parameters.  A default argument should be stable.

Sorry, one more point I left out.  I've stated in the previous thread that the
table.* functions are apparently meant for sequences.  And this holds true with
table.unpack applying the length operator (#t) for the default argument.  So the
odd ball out is the table.pack() api which does not always produce a sequence.

If table.pack were to always produce a sequence such that 
table.pack(1,2,3,nil,5) returned {1,2,3,5} then the table.* api set unifies and
the ambiguity goes away.

table.pack() explanation would read as - Packs all given arguments into a
sequence, discarding nil values.  This would keep in line with Section 2.1 of
the manual, and the rest of the table.* api.  Obviously, that would change this
particular api's use case.

chris