List 如何在函数返回的列表上使用“添加到列表”
我有一个返回列表的函数。它可以返回空白列表或数字列表。我想将List 如何在函数返回的列表上使用“添加到列表”,list,elisp,List,Elisp,我有一个返回列表的函数。它可以返回空白列表或数字列表。我想将添加到列表应用于返回值。可能吗 (defun return-list () body....) (setq test (add-to-list (return-list) 1) ) 函数对变量而不是列表进行操作。 例如: 如果要无条件添加到列表中,请使用对位置进行操作的宏: (push 1 test) 但是,在您的情况下,您可以执行更简单的操作: (setq test (cons 1 (return-list))
添加到列表
应用于返回值。可能吗
(defun return-list () body....)
(setq test (add-to-list (return-list) 1) )
函数对变量而不是列表进行操作。
例如:
如果要无条件添加到列表中,请使用对位置进行操作的宏:
(push 1 test)
但是,在您的情况下,您可以执行更简单的操作:
(setq test (cons 1 (return-list)))
如果要仅在元素尚未存在时添加该元素,请使用也在位置上操作的宏:
(pushnew 1 test)
;; `test' is now (1)
(pushnew 1 test)
;; `test' is still (1)
事实上,我们建议使用
cl-pushnew
(从cl-lib
)而不是pushnew
(从旧的cl
库)。但主要的一点是,添加到列表中
仅用于对自定义变量等操作。
(pushnew 1 test)
;; `test' is now (1)
(pushnew 1 test)
;; `test' is still (1)