help-gnu-emacs
[Top][All Lists]
Advanced

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

Is this use of nreverse a good practice?


From: Marcin Borkowski
Subject: Is this use of nreverse a good practice?
Date: Sun, 01 Feb 2015 13:08:17 +0100

Hi there,

I'm writing a small function which should build a list and return it.
What I'm doing is more or less this:

(defun myfunc ()
  (let ((list-var))
    (while CONDITION
      (DO-SOMETHING)
      (push SOME-ELEMENT list-var))
    (nreverse list-var)))

A more concrete example:

(defun reverse-range (n)
  (let ((list-var))
    (while (> n 0)
      (push n list-var)
      (decf n))
    (nreverse list-var)))

(reverse-range 5)

⇒ (5 4 3 2 1)

Is this usage of `nreverse' correct?  I guess it is, since list-var is
only a temporary variable and destructing it doesn't bother me.
However, I'm never sure I'm doing things right when using
nconc/nreverse, so I though I'd better ask...

TIA,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

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