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

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

Re: replacing a certain element in a list with another


From: Kai Grossjohann
Subject: Re: replacing a certain element in a list with another
Date: Thu, 16 Oct 2003 22:52:23 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (berkeley-unix)

Roland Winkler <Roland.Winkler@physik.uni-erlangen.de> writes:

> The function `reverse' does not alter the original argument LIST. On
> the other hand, `nreverse' reverses LIST by modifying cdr pointers.
> Why does the docstring of `reverse' say
>
>   See also the function `nreverse', which is used more often.
>
> Yet, the info page for `nreverse' says
>
>   To avoid confusion, we usually store the result of `nreverse' back
>   in the same variable which held the original list:
>
> Wouldn't it then be more natural to use `reverse' from the
> beginning? Or am I missing something here??

Well, (nreverse x) does destructively modify the list x, but
afterwards the value if x is not what you think:

*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (setq x (list 1 2 3 4))
(1 2 3 4)

ELISP> (nreverse x)
(4 3 2 1)

ELISP> x
(1)

ELISP> 

Clear?

Kai


reply via email to

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