[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
- Re: replacing a certain element in a list with another,
Kai Grossjohann <=
- Re: replacing a certain element in a list with another, Roland Winkler, 2003/10/22
- Re: replacing a certain element in a list with another, Barry Margolin, 2003/10/22
- Re: replacing a certain element in a list with another, Barry Margolin, 2003/10/23
- Re: replacing a certain element in a list with another, Roland Winkler, 2003/10/23
- Re: replacing a certain element in a list with another, Barry Margolin, 2003/10/23
- Re: replacing a certain element in a list with another, Roland Winkler, 2003/10/24
- Re: replacing a certain element in a list with another, Barry Margolin, 2003/10/24