next up previous
Next: 3.10 括弧を付けたり,はずしたりする関数 Up: 3 リスト構造の変更 Previous: 3.8 データの挿入

3.9 データの置換

同様にnth番目の要素を置換する関数としてnth-replaceは 以下のようになる.
<cl> (setq a '(1 2 3 4))
(1 2 3 4) 
<cl> (defun nth-replace (nth data sexp)
         (rplaca (nthcdr nth sexp) data)
         sexp)
NTH-REPLACE 
<cl> (nth-replace 0 'a a)
(A 2 3 4) 
<cl> a
(A 2 3 4) 
<cl> 

lll
((10 c) c d e)
(nth-replace 1 20 lll)
((10 c) 20 d e)
lll
((10 c) 20 d e)
(nth-delete 1 lll)
((10 c) d e)
lll
((10 c) d e)
(nth-insert 1 30 lll)
((10 c) 30 d e)
lll
((10 c) 30 d e)


generated through LaTeX2HTML. M.Inaba 平成18年5月7日