Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
数字のリストがある場合
(setq numbers '(10 11 12))
そして、たとえば 3 番目の数字をインクリメントしたい場合、次のように実行できます。
(setf (nth 2 numbers) (1+ (nth 2 numbers)))
しかし、「(n番目の2つの数字)」を繰り返さなければならないのは好きではありません。これを書く方法はありますが、「(nth 2 numbers)」への参照は 1 つしかありませんか?
まさにそのためのマクロがあります:
(incf (nth 2 numbers))
追加の引数として追加する値を指定できます。
これは、nthへの二重呼び出しなしでそれを行う純粋なemacs Lispの方法です...
(defun inc-list(n lst) (let ((nc (nthcdr n lst))) (setcar nc (1+ (car nc))) lst))