Lisp-如何打破';配对';名单?
在运行一段代码后,我将获得以下输出(两个单独的列表对):Lisp-如何打破';配对';名单?,lisp,autocad,autolisp,Lisp,Autocad,Autolisp,在运行一段代码后,我将获得以下输出(两个单独的列表对): (“a”)(“a”) 如何将这对列表合并为一个? i、 e.我想要以下输出: (“a”a”) 为了澄清,我的代码是: (defun c:TEST () (setq a (ssget)); I select a line here (setq b (assoc 8 (entget (ssname a 0)))); gets me all dotted pairs containing 8 (setq c (list
(“a”)(“a”)
如何将这对列表合并为一个?
i、 e.我想要以下输出:
(“a”a”)
为了澄清,我的代码是:
(defun c:TEST ()
(setq a (ssget)); I select a line here
(setq b (assoc 8 (entget (ssname a 0)))); gets me all dotted pairs containing 8
(setq c (list (cdr b))); gets second elements of each pair (strings in this case) and converts them to two separate lists
(print c)
)
我已经讨论了您的问题,据我所知,我正在努力解决您的问题,您似乎试图获取该行的层名称。
如果您像前面提到的那样运行测试函数,它会返回两次
(“a”)
,因为第一次是由于代码中的(打印c)
,第二次是作为函数输出值。输出为单列表(“a”)
,但它在命令提示符中写入两次。我以为您误解了这里的意思。如果在函数末尾键入
(princ)
,则输出为(“a”)
请记住,AutoLISP始终将函数的最后一条语句作为函数值返回,以获取更多详细的开发人员文档
此外,您可以在AutoLISP中找到打印值的详细信息,开发者可以使用“print”、“princ”、“prin1”和“prompt”命令 下面我写一些函数,可以帮助你更好地理解这个概念
;
(defun c:TEST()
(setq a (ssget))
(setq b (assoc 8 (entget (ssname a 0))))
(setq c (list (cdr b)))
(print c)
;output-> ("a") ("a")
)
(defun c:TEST1 ()
(setq a (ssget))
(setq b (assoc 8 (entget (ssname a 0))))
(setq c (list (cdr b)))
(print c)
(princ);return nothing
;output-> ("a")
)
(defun c:TEST2()
(setq a (ssget))
(setq b (assoc 8 (entget (ssname a 0))))
(setq c (list (cdr b)))
(print c)
(princ "last statement");return nothing
;output-> ("a") last statement"last statement"
)
(defun c:TEST3()
(setq a (ssget))
(setq b (assoc 8 (entget (ssname a 0))))
(setq c (list (cdr b)))
(print c)
(princ "last statement");return nothing
(princ)
;output-> ("a") last statement
)
如果运行测试,则输出为(“a”)(“a”)
如果运行test1,则输出为
(“a”)
如果运行test2,则输出是最后一个语句“最后一个语句”
这里您可以看到“last statement”是两次,因为同样的原因AutoLISP总是将函数的最后一条语句作为函数值返回 如果运行test3,则输出是最后一条语句
希望这有助于使用
APPEND
将多个列表追加到一个列表中。函数如何返回多个列表?您确定第一个(“a”)
不是打印的(c
),第二个与返回值相同吗?我是@Sylvester;一个(打印c)
不会产生两个值。printf
函数,因此如果它是函数的最后一个表达式,则该函数将返回打印的内容。如果您从某个交互式侦听器(“REPL”或“read-eval-print-loop”)运行该函数,您将看到打印的输出和返回的值再次打印。我是哑巴。你说得对。我觉得自己很愚蠢。谢谢如何标记为已解决?