如何替换表中第n个元素?
例如一个表,lst=(n0 n1 … nj… nn)
我想用mj替换nj得到新的表:
lst=(n0 n1 … mj… nn)
如何做到呀!
就是替换第j+1个元素,或者通俗的说第n个元素,一个意思。
(defun repn (lst n new / nlst)
(if (> (length lst) n) (progn
(setq i 0)
(foreach x lst (setq nlst (append nlst (list (if (= i n) new x))) i (1+ i)))
))
nlst
)
构建一个新的表,对旧表循环 构建一个新的表,对旧表循环 本帖最后由 Andyhon 于 2012-4-28 21:25 编辑
Ref Link:
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/change-only-one-element-of-list/td-p/885496/page/2
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/change-only-one-element-of-list/td-p/885496/page/3
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/List-Replace-a-Member-with-another/td-p/827778
http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Removing-element-in-known-location-of-list/td-p/795694
谢谢大家,好多回复呀。。。。 http://bbs.mjtd.com/thread-92135-1-1.html
有此函数mdfylist ZZXXQQ 发表于 2012-4-28 20:35
这个怎么用啊?不太会用。{:1_1:} chenyizhen28 发表于 2023-1-14 00:02
这个怎么用啊?不太会用。
加载后执行:
(repn lst n new)
页:
[1]
2