Elisp交互功能名称 [英] Elisp interactive function name
问题描述
我正在尝试使用交互式功能名称功能。在emacs lisp手册中,它说:
I'm trying to use the interactive function name feature. On emacs lisp manual it says:
'a'
函数名称(即满足fboundp的符号)。现有,完成,提示
‘a’ A function name (i.e., a symbol satisfying fboundp). Existing, Completion, Prompt.
所以我尝试了一个小的测试代码:
So I tried it with a small test code:
(defun testfun1 ()
(message "hello, world!"))
(defun test (abcd)
(interactive "aTheme name: ")
(abcd))
Emacs给出错误说,
Emacs gives an error saying,
test:符号的函数定义为void:abcd
test: Symbol's function definition is void: abcd
我试图用fboundp测试abcd,它返回t。所以我很感动如何在交互式中使用'a'选项。
任何身体都可以提供一些提示?
I tried to test abcd with fboundp, it returns t. So I'm quite confused about how to use the 'a' option in interactive. Any body can give some hints?
推荐答案
您的功能 test
接收其参数 abcd
作为一个函数,但是您不能通过将符号引用到要评估的列表的第一个位置来调用函数。由于Emacs Lisp是一个Lisp-2,所以提供给交互式查询的函数的引用存储在符号 abcd
的值插槽,而不是其功能插槽。列表的评估规则,如
Your function test
receives its argument abcd
as a function, but you can't just invoke a function by putting a symbol referencing it in the first position of a list to be evaluated. Since Emacs Lisp is a Lisp-2, the reference to the function provided to the interactive query is stored in symbol abcd
's value slot, not its function slot. The evaluation rules for a list like
(abcd)
涉及查看第一个对象的功能槽,如果该对象是符号,那就是您的情况。如果您想要调用符号值槽中引用的函数,则需要 funcall
功能:
involve looking in the first object's function slot if that object is a symbol, which it is in your case. If instead you wish to invoke a function referenced in a symbol's value slot, you need the funcall
function:
(funcall abcd)
说:拿 abcd
,从值槽中获取值,如果它是一个函数,在这里调用它,就像我们在列表的第一个位置在符号的功能插槽中或直接引用函数对象。
That says, "Take abcd
, grab the value out of its value slot, and, provided it's a function, call it here, just as we would have if that function had been referenced in the list's first position either in a symbol's function slot or by a direct reference to the function object."
这里是回答类似的问题,引用有助于您探测
Here's an answer to a similar question with references useful to allow you probe further.
这篇关于Elisp交互功能名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!