|
From: | richardeng |
Subject: | Re: How could I modify list element? |
Date: | Wed, 10 Dec 2008 01:43:23 +0800 |
User-agent: | Thunderbird 2.0.0.18 (Windows/20081105) |
Alan Mackenzie wrote:
On Tue, 9 Dec 2008, richardeng wrote:Hi all, setcar/setcdr is not convenient. In a long list, ex. (setq a '(a b c d e f g)) I want to change 'e to 'E. I need a function: (set-list-elt list old-elt new-elt) How? translate list to vector, modify, then turn it back???Try this (not tested): (defun change-nth (liszt, n, nieuw) (while (> n 0) (setq liszt (cdr liszt) n (1- n))) (if liszt (setcar liszt nieuw)))
(setq aaa '(1 2 3 4 5 b a "ccc")) (change-nth aaa 3 'BB) aaa --> (1 2 3 BB 5 b a "ccc") , it works, thank you!
[Prev in Thread] | Current Thread | [Next in Thread] |