如何将函数作为参数传递给elisp? [英] How do I pass a function as a parameter to in elisp?
本文介绍了如何将函数作为参数传递给elisp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在 elisp 中将一种方法传递给另一种方法,然后让那个方法执行它.下面是一个例子:
I'm trying to pass one method to another in elisp, and then have that method execute it. Here is an example:
(defun t1 ()
"t1")
(defun t2 ()
"t1")
(defun call-t (t)
; how do I execute "t"?
(t))
; How do I pass in method reference?
(call-t 't1)
推荐答案
首先,我不确定将函数命名为 t
是否有帮助,因为 't' 用作 真值 lisp.
First, I'm not sure that naming your function t
is helping as 't' is used as the truth value in lisp.
也就是说,以下代码对我有用:
That said, the following code works for me:
(defun test-func-1 () "test-func-1"
(interactive "*")
(insert-string "testing callers"))
(defun func-caller (callee)
"Execute callee"
(funcall callee))
(func-caller 'test-func-1)
请注意funcall"的使用,它会触发实际的函数调用.
Please note the use of 'funcall', which triggers the actual function call.
这篇关于如何将函数作为参数传递给elisp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文