unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: Fix nreverse
@ 2014-05-21 14:07 Barry OReilly
  2014-05-21 17:17 ` Stefan Monnier
  2014-05-22  0:15 ` Leo Liu
  0 siblings, 2 replies; 6+ messages in thread
From: Barry OReilly @ 2014-05-21 14:07 UTC (permalink / raw)
  To: sdl.web, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 904 bytes --]

> I also fix nreverse doc-string not to mention its implementation
> details.

That the sequence is mutated is not an implementation detail. It is a
side effect that should be documented as part of the interface.

  (let ((lst '(1 2 3)))
    (message "Reversed: %s" (reverse lst))
    (message "Original: %s" lst)
    (message "NReversed: %s" (nreverse lst))
    (message "Original: %s" lst))
  ;; Output:
  ;; Reversed: (3 2 1)
  ;; Original: (1 2 3)
  ;; NReversed: (3 2 1)
  ;; Original: (1)

The user may well care about the difference.

> This would make nreverse and reverse symmetric.

  (let ((str "123"))
    (message "Reversed: %s" (reverse str))
    (message "Original: %s" str)
    (message "NReversed: %s" (nreverse str))
    (message "Original: %s" str))
  ;; Output:
  ;; Reversed: 321
  ;; Original: 123
  ;; NReversed: 321
  ;; Original: 123

This is not symmetrical to the lst example.

[-- Attachment #2: Type: text/html, Size: 1177 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Fix nreverse
@ 2014-05-21  2:20 Leo Liu
  2014-05-21  2:53 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Leo Liu @ 2014-05-21  2:20 UTC (permalink / raw)
  To: emacs-devel

Hi there,

I find the decision to leave out strings in nreverse inconvenient. Why
don't we dispatch to reverse when SEQ is string instead of throwing an
error? This would make nreverse and reverse symmetric. I hope "N" mean
we `may' not `must' destructively modify the argument. Objections?

Leo




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-05-22  0:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-21 14:07 Fix nreverse Barry OReilly
2014-05-21 17:17 ` Stefan Monnier
2014-05-22  0:15 ` Leo Liu
  -- strict thread matches above, loose matches on Subject: below --
2014-05-21  2:20 Leo Liu
2014-05-21  2:53 ` Stefan Monnier
2014-05-21  4:06   ` Leo Liu

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).