[Top][All Lists]

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

Re: replacing a certain element in a list with another

From: Roland Winkler
Subject: Re: replacing a certain element in a list with another
Date: 30 Sep 2003 20:27:28 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Stefan Monnier <address@hidden> writes:

> > Well, it depends on whether the OP wants to return a new list or to modify
> > the original list.
> That's exactly what was meant by "have good reasons to do it".  Mixing the
> in-place-update style with the create-new-stuff style (aka imperative style
> vs functional style) is a common source of error because it generally makes
> the code more "subtle" (more difficult to understand).  Since elisp usually
> copies things around, inplace-update operations such as nconc, nreverse,
> setcar, setcdr, delete, delq, ... should be used with caution.

Kind of a related question:

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


reply via email to

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