Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如何在函数返回的列表上使用“添加到列表”_List_Elisp - Fatal编程技术网

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)