修改列表
我有一个这样的清单(1“A”“B”“C”2“A”“B”)
我将如何获得((1)(“A”“B”“C”)(2)(“A”“B”))?
又快又脏。。。
(defun test (lst / temp newlist)
(foreach x (reverse lst)
(if (numberp x)
(setq temp (not (setq newlist (cons (list x temp) newlist))))
(setq temp (cons x temp))
)
)
newlist
) 谢谢我也在做类似的事情,但我的一直没有成功。 任何时候。就像我说的‘date=’很快又脏。
这是我的尝试
(defun test (ls / a b c)
(foreach j ls
(if (numberp j)
(if a
(setq c (cons
(vl-list* (reverse b) a) c) a j b nil)
(setq a j b nil))
(setq b (cons j b))
)
)
(setq newllist (reverse (cons (vl-list* (reverse b) a) c)))
)
(test '(1 "A" "B" "C" 2 "A" "B"))
((("A" "B" "C") . 1) (("A" "B") . 2))
但是为了我的爱,我不能展示/构建虚线对来匹配丹中尉的腿要求的结果
((1.(“A”“B”“C”))(2.(“A”“B”))
Alanjt公司
我本来会像你的代码那样做,但你的代码最终是一个非点对。。
有什么想法吗?
很高兴论坛又开始运行了
请不要忘记,点对的第二项应该是原子,因此OP的请求是AutoLISP不支持的构造。
当做
米尔恰 这没有意义。您仍然可以关联非点对列表。
例如(使用我的sub)
Command: (assoc 2 (test '(1 "A" "B" "C" "D" 2 "D" "F" "R" 5 "D" "E" "T")))
(2 ("D" "F" "R"))
恐怕这与访问以键值样式存储的数据的一致性有关,同时仍保留“值”的数据类型(请参阅相关列表):
(cdr '(2 . 1)) will return 1
(cdr '(2 1 2 3)) will return '(1 2 3)
(cdr '(2 (1 2 3))) will return '((1 2 3))
当做
米尔恰 只需使用cadr而不是cdr来检索子列表。
页:
[1]