[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Side effects of `sort'
From: |
Dave Abrahams |
Subject: |
Re: Side effects of `sort' |
Date: |
Thu, 01 Mar 2012 16:04:19 -0500 |
User-agent: |
Gnus/5.130004 (Ma Gnus v0.4) Emacs/24.0.93 (darwin) |
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