【发布时间】:2015-07-28 00:11:35
【问题描述】:
我不明白如何在 emacs lisp 中评估“&可选参数”。
我的代码是:
(defun test-values (a &optional b)
"Function with an optional argument (default value: 56) that issues a
message indicating whether the argument, expected to be a
number, is greater than, equal to, or less than the value of
fill-column."
(interactive "p")
(if (or (> a b)(equal a b))
(setq value a)
(setq value fill-column)
(message "The value of payina is %d" fill-column))
**(if (equal b nil)
(setq value 56)))**
在第一部分,如果我评估 (test-values 5 4) 或 (test-values 5 5),一切都完美。
但是,当我评估 (test-values 5 ()) 或 (test-values 5 nil) 时,出现以下错误:
**Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
>(5 nil)
(or (> a b) (equal a b))
(if (or (> a b) (equal a b)) (setq value a) (setq value fill-column)
(message "The value of payina is %d" fill-column))
test-values(5 nil)
eval((test-values 5 nil) nil)
eval-last-sexp-1(nil)
eval-last-sexp(nil)
call-interactively(eval-last-sexp nil nil)
command-execute(eval-last-sexp)**
有人可以帮帮我吗?谢谢。
【问题讨论】:
-
函数
>需要两个数字参数。它收到的参数之一是nil。您为参数b传递了nil值。(> 5 nil)不计算。 -
非常感谢。我会理解可选参数的概念,谢谢。
-
“payina”是什么意思?
标签: emacs elisp optional-parameters optional-arguments optional-values