GNU bug report logs - #18837
25.0.50; `sort` -- modify function to preserve original list.

Previous Next

Package: emacs;

Reported by: Keith David Bershatsky <esq <at> lawlist.com>

Date: Sat, 25 Oct 2014 21:04:01 UTC

Severity: wishlist

Found in version 25.0.50

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 18837 in the body.
You can then email your comments to 18837 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#18837; Package emacs. (Sat, 25 Oct 2014 21:04:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Keith David Bershatsky <esq <at> lawlist.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 25 Oct 2014 21:04:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Keith David Bershatsky <esq <at> lawlist.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; `sort` -- modify function to preserve original list.
Date: Sat, 25 Oct 2014 14:03:25 -0700
The doc-string for the function `sort` states that `SEQ is modified by side effects`; however, it does not state in what way the original list gets modified or why such a feature might somehow be useful.  I attempted to find out the answer to this question on `superuser.com`, however, the community has expressed an interest in closing the question without offering an explanation on this issue:

http://superuser.com/questions/831608/emacs-sort-usefulness-of-side-effect-modifying-initial-list

In my use case, I want to preserve an initial list that is set to a let-bound variable so that I can use it again elsewhere in the function.  To achieve this objection, I used `copy-list`.

Unless the modified `SEQ` is somehow useful, perhaps it would be appropriate to modify the function `sort` so that it preserves the initial list.

Thanks,

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In GNU Emacs 25.0.50.1 (x86_64-apple-darwin10.8.0, NS appkit-1038.36 Version 10.6.8 (Build 10K549))
 of 2014-10-01 on MP.local
Repository revision: 117996 dmantipov <at> yandex.ru-20141001132108-zdsxru2390mqyjlu
Windowing system distributor `Apple', version 10.3.1038
Configured using:
 `configure --with-ns'

Configured features:
ACL LIBXML2 ZLIB

Important settings:
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  sd-mode: t
  sb-mode: t
  tb-mode: t
  shell-dirtrack-mode: t
  cm-mode: t
  bc-mode: t
  as-mode: t
  ds-mode: t
  ml-mode: t

Recent input:

Recent messages:

Load-path shadows:
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/md4 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/md4
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/hex-util hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/hex-util
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/sasl hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/sasl
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/sasl-ntlm hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/sasl-ntlm
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/sasl-digest hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/sasl-digest
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/sasl-cram hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/sasl-cram
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/ntlm hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/ntlm
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/hmac-md5 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/hmac-md5
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/hmac-def hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/net/hmac-def
/Users/HOME/.0.data/.0.emacs/.0.wl/rfc2368 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/mail/rfc2368
/Users/HOME/.0.data/.0.emacs/.0.wl/utf7 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/gnus/utf7
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/smime hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/gnus/smime
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/pgg hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/pgg-pgp5 hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-pgp5
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/pgg-pgp hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-pgp
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/pgg-parse hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-parse
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/pgg-gpg hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-gpg
/Users/HOME/.0.data/.0.emacs/.0.apel_flim_simi/pgg-def hides /Users/HOME/.0.data/.0.emacs/Emacs_10_01_2014.app/Contents/Resources/lisp/obsolete/pgg-def

Features:
(shadow mime-setup mail-mime-setup semi-setup mime-image modb-standard
elmo-imap4 mule-util eieio-opt speedbar sb-image ezimage dframe
emacsbug lawlist-desktop frameset lawlist-colors reporter lawlist-dv
lawlist-mc rect lawlist-ztree lawlist-wl elmo-nntp wl-demo wl-news
wl-address wl-thread wl wl-e21 wl-draft elmo-pop3 wl-template elmo-net
elmo-cache elmo-map elmo-dop wl-folder wl-spam wl-action wl-summary
wl-refile wl-message wl-mime pgg mime-pgp wl-util pp elmo-flag
elmo-localdir mime-play filename mime-edit eword-encode pgg-parse pccl
pccl-20 pgg-def signature sendmail elmo-mime mmelmo-buffer mmelmo-imap
mime-view mime-conf calist semi-def mmimap mime-parse mmbuffer
mmgeneric elmo-filter elmo-multi elmo-spam elsp-header elsp-generic
elmo elmo-signal wl-highlight wl-vars wl-version elmo-msgdb modb
modb-generic modb-entity luna mime elmo-util emu invisible inv-23 poem
poem-e20 poem-e20_3 eword-decode std11 elmo-date elmo-vars
elmo-version w3m-load mime-w3m w3m browse-url doc-view jka-compr
image-mode w3m-hist w3m-fb bookmark-w3m w3m-ems w3m-ccl ccl
w3m-favicon w3m-image w3m-proc w3m-util lawlist-dired dired-aux
lawlist-vr-hr lawlist-ws disp-table lawlist-calc lawlist-flyspell
lawlist-yas lawlist-tex-mode skeleton compare-w lawlist-txt-mode
lawlist-tabbar lawlist-github ido view vc-git vc vc-dispatcher tramp
tramp-compat tramp-loaddefs trampver shell thingatpt time-stamp rx
log-view log-edit pcvs-util add-log help-mode grep compile find-lisp
epa epg epg-config ediff-merg ediff-wind ediff-diff ediff-mult
ediff-help ediff-init ediff-util ediff ert ewoc debug eieio-base
diff-mode conf-mode autorevert filenotify lorg-calendar org-element
lorg-search org-agenda context-menu dired-read-filename
lawlist-toodledo url-http url-auth url-gw url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf url-util
url-parse auth-source eieio eieio-core password-cache url-vars mailcap
json xml lawlist-org lawlist-calendar derived org byte-opt bytecomp
byte-compile cconv org-macro org-footnote org-pcomplete pcomplete
org-list org-faces org-entities org-version ob-emacs-lisp ob ob-tangle
org-src ob-ref ob-lob ob-table ob-keys ob-exp ob-comint comint
ansi-color ring ob-core ob-eval org-compat org-macs org-loaddefs
cal-menu calendar cal-loaddefs noutline outline gnus-sum gnus-group
gnus-undo gnus-start gnus-cloud nnimap nnmail mail-source tls utf7 mel
path-util mime-def alist mcharset mcs-20 mcs-e20 pcustom pces pces-e20
pces-20 broken poe pym static apel-ver product netrc nnoo parse-time
gnus-spec gnus-int gnus-range message dired format-spec mml mml-sec
mm-decode mm-bodies mm-encode gmm-utils mailheader gnus-win
lawlist-frame lawlist-cm lawlist-bbdb gnus gnus-ems nnheader gnus-util
mail-utils wid-edit mail-parse rfc2231 rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mailabbrev mail-extr rfc822 cl timezone
lawlist-init pcase cl-macs gv advice help-fns easy-mmode edmacro
kmacro cl-loaddefs cl-lib savehist server ps-print ps-def lpr
find-func saveplace easymenu time-date tooltip electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel ns-win tool-bar dnd fontset
image regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
cocoa ns multi-tty emacs)

Memory information:
((conses 16 1096676 58375)
 (symbols 48 62784 0)
 (miscs 40 214 364)
 (strings 32 147723 21599)
 (string-bytes 1 4679349)
 (vectors 16 42737)
 (vector-slots 8 761520 19326)
 (floats 8 1105 51)
 (intervals 56 5302 730)
 (buffers 976 15))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18837; Package emacs. (Sun, 26 Oct 2014 02:45:01 GMT) Full text and rfc822 format available.

Message #8 received at 18837 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Keith David Bershatsky <esq <at> lawlist.com>
Cc: 18837 <at> debbugs.gnu.org
Subject: Re: bug#18837: 25.0.50;
 `sort` -- modify function to preserve original list.
Date: Sat, 25 Oct 2014 22:44:45 -0400
> The doc-string for the function `sort` states that `SEQ is modified by
> side effects`; however, it does not state in what way the original
> list gets modified or why such a feature might somehow be useful.

The "usefulness" is to avoid allocating another list in the case where
the unsorted list won't be used later on anyway.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18837; Package emacs. (Sun, 26 Oct 2014 05:06:02 GMT) Full text and rfc822 format available.

Message #11 received at 18837 <at> debbugs.gnu.org (full text, mbox):

From: Keith David Bershatsky <esq <at> lawlist.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18837 <at> debbugs.gnu.org
Subject: Re: bug#18837: 25.0.50;
 `sort` -- modify function to preserve original list.
Date: Sat, 25 Oct 2014 22:04:55 -0700
Thank you, Stefan, for taking a look at this Emacs report (#18837).

Here is my workaround:

    (defun lawlist-sort (seq predicate)
      (let ((disposable-list (copy-list seq)))
        (sort disposable-list predicate)))

There may be situations where `copy-list` might not work, but that is beyond my present level of understanding / knowledge.  I suppose that there might be some time consumption issues involved with the function `copy-list` for extremely complex lists, but none of my lists would ever get so large/complex that this would be an issue.

Thanks,

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

At Sat, 25 Oct 2014 22:44:45 -0400,
Stefan Monnier wrote:
> 
> > The doc-string for the function `sort` states that `SEQ is modified by
> > side effects`; however, it does not state in what way the original
> > list gets modified or why such a feature might somehow be useful.
> 
> The "usefulness" is to avoid allocating another list in the case where
> the unsorted list won't be used later on anyway.
> 
> 
>         Stefan




Reply sent to Stefan Kangas <stefan <at> marxist.se>:
You have taken responsibility. (Mon, 16 Sep 2019 05:31:02 GMT) Full text and rfc822 format available.

Notification sent to Keith David Bershatsky <esq <at> lawlist.com>:
bug acknowledged by developer. (Mon, 16 Sep 2019 05:31:02 GMT) Full text and rfc822 format available.

Message #16 received at 18837-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18837-done <at> debbugs.gnu.org, Keith David Bershatsky <esq <at> lawlist.com>
Subject: Re: bug#18837: 25.0.50; `sort` -- modify function to preserve
 original list.
Date: Mon, 16 Sep 2019 07:30:36 +0200
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> The doc-string for the function `sort` states that `SEQ is modified by
>> side effects`; however, it does not state in what way the original
>> list gets modified or why such a feature might somehow be useful.
>
> The "usefulness" is to avoid allocating another list in the case where
> the unsorted list won't be used later on anyway.

It doesn't seem like there is anything more to do here, so I'm closing
this bug.

Best regards,
Stefan Kangas




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 14 Oct 2019 11:24:12 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 168 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.