% Accessor NTH
Accessor NTH
nth n list => object
(setf (nth n list) new-object)
n - 非負の整数
list - リスト、ドットリストと循環リストも受け付けます。
object - オブジェクト
new-object - オブジェクト
nthは、
listのcar部を「0番目」の要素したときの、
listのn番目の要素を示します。
具体的には次のようになります。
(nth n list) ==  (car (nthcdr n list))
nthは、setfのplaceとして指定できます。
具体的には次のようになります。
(setf (nth n list) new-object) ==  (setf (car (nthcdr n list)) new-object)
(nth 0 '(foo bar baz)) =>  FOO
(nth 1 '(foo bar baz)) =>  BAR
(nth 3 '(foo bar baz)) =>  NIL
(setq 0-to-3 (list 0 1 2 3)) =>  (0 1 2 3)
(setf (nth 2 0-to-3) "two") =>  "two"
0-to-3 =>  (0 1 "two" 3)
なし。
なし。
なし。
なし。