[Top][All Lists]

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

Re: Fix nreverse

From: Barry OReilly
Subject: Re: Fix nreverse
Date: Wed, 21 May 2014 10:07:45 -0400

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

reply via email to

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