unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* 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

* Re: Fix nreverse
  2014-05-21  2:20 Fix nreverse Leo Liu
@ 2014-05-21  2:53 ` Stefan Monnier
  2014-05-21  4:06   ` Leo Liu
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2014-05-21  2:53 UTC (permalink / raw)
  To: Leo Liu; +Cc: emacs-devel

> 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?

I guess it's OK if we change the meaning of nreverse to "may modify
destructively", but then please change the docstring to say so, and
*generically* (rather than saying explicitly how that's interpreted for
each possible type).


        Stefan



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

* Re: Fix nreverse
  2014-05-21  2:53 ` Stefan Monnier
@ 2014-05-21  4:06   ` Leo Liu
  0 siblings, 0 replies; 6+ messages in thread
From: Leo Liu @ 2014-05-21  4:06 UTC (permalink / raw)
  To: emacs-devel

On 2014-05-20 22:53 -0400, Stefan Monnier wrote:
> I guess it's OK if we change the meaning of nreverse to "may modify
> destructively", but then please change the docstring to say so, and
> *generically* (rather than saying explicitly how that's interpreted for
> each possible type).

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

Leo




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

* 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

* Re: Fix nreverse
  2014-05-21 14:07 Barry OReilly
@ 2014-05-21 17:17 ` Stefan Monnier
  2014-05-22  0:15 ` Leo Liu
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2014-05-21 17:17 UTC (permalink / raw)
  To: Barry OReilly; +Cc: sdl.web, emacs-devel

> 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)

This last "Original" value should not be depended upon by the user.


        Stefan



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

* Re: Fix nreverse
  2014-05-21 14:07 Barry OReilly
  2014-05-21 17:17 ` Stefan Monnier
@ 2014-05-22  0:15 ` Leo Liu
  1 sibling, 0 replies; 6+ messages in thread
From: Leo Liu @ 2014-05-22  0:15 UTC (permalink / raw)
  To: emacs-devel

On 2014-05-21 10:07 -0400, Barry OReilly wrote:
> That the sequence is mutated is not an implementation detail. It is a
> side effect that should be documented as part of the interface.

No disagreement and that is how nreverse is documented. What I meant is
really implementation detail i.e. how we set the list pointers to
reverse a list.

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  2:20 Fix nreverse Leo Liu
2014-05-21  2:53 ` Stefan Monnier
2014-05-21  4:06   ` Leo Liu
  -- strict thread matches above, loose matches on Subject: below --
2014-05-21 14:07 Barry OReilly
2014-05-21 17:17 ` Stefan Monnier
2014-05-22  0:15 ` 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).