[Top][All Lists]

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

Side effects of `sort'

From: Daniel Schoepe
Subject: Side effects of `sort'
Date: Thu, 01 Mar 2012 20:58:16 +0100
User-agent: Notmuch/0.11.1+212~gcd799cb (http://notmuchmail.org) Emacs/ (x86_64-pc-linux-gnu)


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?


Attachment: pgpkZEh9J23bH.pgp
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]