gpt4 book ai didi

emacs - 将列表传递给 &rest args

转载 作者:行者123 更新时间:2023-12-04 11:22:16 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to set a part of arguments from a list in Emacs Lisp?

(1 个回答)


7年前关闭。




如何将参数列表传递给 start-process的第四个参数 (PROGRAMS-ARGS) :

(start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)
例如:
(start-process "program-name" nil "program-name" "-p1" "-p2" "-p3" "program-name")
我想通过在列表中收集参数并将列表变量传递给函数参数来做同样的事情,但它不起作用:
(setq program-args (list "-p1" "-p2" "-p3"))

(start-process "program-name" nil "program-name" program-args "program-name")

最佳答案

您应该使用 apply 在这种情况下:

apply calls function with arguments, just like funcall but with one difference: the last of arguments is a list of objects, which are passed to function as separate arguments, rather than a single list.



即,在您的情况下,正确的代码是:
(apply 'start-process
(append (list "program-name" nil "program-name")
program-args
(list "program-name")))

关于emacs - 将列表传递给 &rest args,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17075920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com