[英]elisp , passing functions as arguments and call it, an Eval error happend, why?
我的elisp程序是:
(defun test (f x) (f x))
(test (lambda (x) (* x x)) 10)
運行它,發生錯誤:
* Eval error *符號的函數定義為void:f
Emacs是一個lisp-2,因此函數和變量有不同的命名空間。 因此,在測試中,第二個(fx)中的f與參數列表中的(f)不同。
嘗試
(defun test (f x) (funcall f x))
一切都很好。
這是更正:
(defun test (f x)
(funcall f x))
(test (lambda (x) (* x x)) 10)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.