用笨方法。标记你要修改的列表元素序号,再修改相应序号的元素即可。
下面是将l列表中第n个元素变为a的代码。
;;---------------------=={ Subst Nth }==----------------------;;
;; ;;
;; Substitutes an item at the nth position in a list. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; a - item to substitute ;;
;; n - position in list to make the substitution ;;
;; l - list in which to make the substitution ;;
;;------------------------------------------------------------;;
;; Returns: Resultant list following the substitution ;;
;;------------------------------------------------------------;;
(defun LM:SubstNth ( a n l / i )
(setq i -1)
(mapcar '(lambda ( x ) (if (= (setq i (1+ i)) n) a x)) l)
)