[英]elisp , passing functions as arguments and call it, an Eval error happend, why?
my elisp program is: 我的elisp程序是:
(defun test (f x) (f x))
(test (lambda (x) (* x x)) 10)
run it, an error happened: 运行它,发生错误:
* Eval error * Symbol's function definition is void: f * Eval error *符号的函数定义为void:f
Emacs is a lisp-2, so has a different namespace for functions and variables. Emacs是一个lisp-2,因此函数和变量有不同的命名空间。 So, in test, the f in the second (fx) is not the same as the (f) in the parameter list.
因此,在测试中,第二个(fx)中的f与参数列表中的(f)不同。
Try 尝试
(defun test (f x) (funcall f x))
All is good. 一切都很好。
Here's the correction: 这是更正:
(defun test (f x)
(funcall f x))
(test (lambda (x) (* x x)) 10)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.