Re: Proposal: table.sort returning the sorted table.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Proposal: table.sort returning the sorted table.
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: 2011年4月09日 23:20:23 +0200
Thank you for the prompt reply!
On 09/04/2011 20.27, Luiz Henrique de Figueiredo wrote:
I was wondering whether it would be sensible to modify the table.sort
function so that it returns its first argument.
table.sort does not return the table to avoid giving the impression that
it creates a new table. In other words, it stresses the point that the
sort in performed in place.
Mmmm. I see, but still I'm not truly convinced that it is worth the
inconvenience.
After all, library functions are so few, and the manual clearly states
that table.sort works "in-place" (I find it fairly easy to remember - I
read it the first time and never got it wrong) - there are no other
library functions that may cause "interference" in remembering its
behaviour (if I'm not mistaken, there are no functions whatsoever
returning a new table, besides debug.getinfo and os.date, which are
rather particular in themselves).
<nitpickers-corner mode=":-)" >
On a related note, there is a little inconsistence in this respect:
setmetatable returns its first argument. Although it is not a classical
example of "in-place" modification of a data structure (I must admit
it), it still does modify the "virtual" structure of a table (at least
potentially, depending on what metamethods are defined). Moreover both
setmetatable's arguments are tables, so it could be more confusing than
table.sort. Well, at least it was for me :-)
</nitpickers-corner>
cheers
-- Lorenzo