http://bbs.mjtd.com/forum.php?mod=viewthread&tid=60071&replyID=&skin=1 多功能表操作函数以索引 [替代/添加/删除] 表中元素,支持嵌套表! (defun
fsxm-subst-index
(lst index_lst var / subst0 subst1) (defun
subst0
(lst index var / lst2 position) (cond
((or
(= index T)
(> index (1-
(length lst)))) (append lst var) ) ((>= index 0) (setq position 0) (while
(< position index) (setq lst2 (cons
(car lst) lst2)) (if
(<= position (1- index))(setq lst (cdr lst))) (setq position (1+ position)) ) (append
(reverse lst2) var (cdr lst)) ) ((< index 0) (append var lst) ) ) ) (defun
subst1
(lst index_lst var / index) (if
(cadr index_lst) (progn
(setq index (car index_lst)) (subst1 lst (list index) (list
(subst1 (nth index lst)
(cdr index_lst) var)) ) ) (subst0 lst (car index_lst) var) ) ) (if
(listp var) t (setq var (list var))) (if
(listp index_lst) t (setq index_lst (list index_lst))) (subst1 lst index_lst var) ) (defun
fsxm-subst-index
(lst index_lst var / subst0 subst1) (defun
subst0
(lst index var / lst2 position) (cond
((or
(= index T)
(> index (1-
(length lst)))) (append lst var) ) ((>= index 0) (setq position 0) (while
(< position index) (setq lst2 (cons
(car lst) lst2)) (if
(<= position (1- index))(setq lst (cdr lst))) (setq position (1+ position)) ) (append
(reverse lst2) var (cdr lst)) ) ((< index 0) (append var lst) ) ) ) (defun
subst1
(lst index_lst var / index) (if
(cadr index_lst) (progn
(setq index (car index_lst)) (subst1 lst (list index) (list
(subst1 (nth index lst)
(cdr index_lst) var)) ) ) (subst0 lst (car index_lst) var) ) ) (if
(listp var) t (setq var (list var))) (if
(listp index_lst) t (setq index_lst (list index_lst))) (subst1 lst index_lst var) )使用方法如: (setq lst '(0 1 2 (30 31 32 (330 331 332)) 4 5 6 (70 71 72) 8 9)) 替代 (fsxm-subst-index lst 2 "test") ->(0 1 "test" (30 31 32 (330 331 332)) 4 5 6 (70 71 72) 8 9) 删除 (fsxm-subst-index lst 2 nil) ->(0 1 (30 31 32 (330 331 332)) 4 5 6 (70 71 72) 8 9) 批量插入 (fsxm-subst-index lst '(3 3 0.5) '("test1" "test2")) ->(0 1 2 (30 31 32 (330 "test1" "test2" 331 332)) 4 5 6 (70 71 72) 8 9) |