From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dave Abrahams Newsgroups: gmane.emacs.devel Subject: Re: Side effects of `sort' Date: Thu, 01 Mar 2012 16:04:19 -0500 Message-ID: References: <8762eoum93.fsf@schoepe.localhost> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1330637113 12660 80.91.229.3 (1 Mar 2012 21:25:13 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 1 Mar 2012 21:25:13 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 01 22:25:13 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S3DUu-000586-HM for ged-emacs-devel@m.gmane.org; Thu, 01 Mar 2012 22:25:12 +0100 Original-Received: from localhost ([::1]:60434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3DUt-0001Bl-SG for ged-emacs-devel@m.gmane.org; Thu, 01 Mar 2012 16:25:11 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:45704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3DUr-0001AR-76 for emacs-devel@gnu.org; Thu, 01 Mar 2012 16:25:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S3DUp-0006rb-8w for emacs-devel@gnu.org; Thu, 01 Mar 2012 16:25:08 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:44775) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3DUp-0006ps-1r for emacs-devel@gnu.org; Thu, 01 Mar 2012 16:25:07 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1S3DUl-00053Y-PZ for emacs-devel@gnu.org; Thu, 01 Mar 2012 22:25:03 +0100 Original-Received: from 207-172-223-249.c3-0.smr-ubr3.sbo-smr.ma.static.cable.rcn.com ([207.172.223.249]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 01 Mar 2012 22:25:03 +0100 Original-Received: from dave by 207-172-223-249.c3-0.smr-ubr3.sbo-smr.ma.static.cable.rcn.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 01 Mar 2012 22:25:03 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 32 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 207-172-223-249.c3-0.smr-ubr3.sbo-smr.ma.static.cable.rcn.com User-Agent: Gnus/5.130004 (Ma Gnus v0.4) Emacs/24.0.93 (darwin) Cancel-Lock: sha1:cR5xzoKF0TBTcGzfOikBEGyStZ4= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:148868 Archived-At: on Thu Mar 01 2012, Daniel Schoepe wrote: > Hi, > > according to describe-function, `sort' modifies its input list, but not > in any way that the programmer can rely on. (For example, '(2 1 3) > becomes '(2 3)). I assume the precise thing that ends up in the original > list is an implementation detail and being able to "destroy" the > original list has some performance benefits. > > Personally, I find this behavior very surprising and think it would make > more sense to either set the input list to the final sorting result (in > addition to returning it) or not to modify the input. In the current > situation, one basically has to do something like (setq foo (sort foo)) > anyway if one wants to continue using foo (or pass a copy of foo to sort > instead), which would no longer be necessary after this change (modulo > backwards compatibility). > > Is there some rationale for sort working the way it does, that I am > missing here? Lisp doesn't really have access to "the input list" in any real sense: (sort (identity x)) do you expect x to be rebound? -- Dave Abrahams BoostPro Computing http://www.boostpro.com