all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dave Abrahams <dave@boostpro.com>
To: emacs-devel@gnu.org
Subject: Re: Side effects of `sort'
Date: Thu, 01 Mar 2012 16:04:19 -0500	[thread overview]
Message-ID: <m2sjhsdodo.fsf@boostpro.com> (raw)
In-Reply-To: 8762eoum93.fsf@schoepe.localhost


on Thu Mar 01 2012, Daniel Schoepe <daniel-AT-schoepe.org> 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




  parent reply	other threads:[~2012-03-01 21:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-01 19:58 Side effects of `sort' Daniel Schoepe
2012-03-01 20:52 ` Tassilo Horn
2012-03-01 21:04 ` Dave Abrahams [this message]
2012-03-01 21:34   ` Daniel Schoepe
2012-03-01 22:25   ` Stefan Monnier
2012-03-02  6:13     ` Miles Bader

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2sjhsdodo.fsf@boostpro.com \
    --to=dave@boostpro.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.