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

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

replacing a certain element in a list with another


From: Klaus Berndl
Subject: replacing a certain element in a list with another
Date: 30 Sep 2003 10:38:10 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Suppose i have the following list:

'(a b c d)

What is a good way to replace one of the list-elements with another, so foe
example replacing the 'c with 'e?

But: i do not want using any c-functions, so i would prefer a solution without
using `substitute'!

Is the solution easier if i always want to replace the last element of the
list?

I think so, because it could be:

(defvar my-list '( a b c d))

(let ((temp-l (nreverse my-list)))
  (setcar temp-l 'e)
  (nreverse temp-l))

Is this a good elisp-solution? 

Thanks for help,
Klaus
 
-- 
Klaus Berndl                    mailto: klaus.berndl@sdm.de
sd&m AG                         http://www.sdm.de
software design & management    
Thomas-Dehler-Str. 27, 81737 München, Germany
Tel +49 89 63812-392, Fax -220


reply via email to

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