如何在emacs lisp中计算“&可选参数”?
我不明白如何在emacs lisp中计算&optional参数 我的代码是:如何在emacs lisp中计算“&可选参数”?,emacs,elisp,optional-parameters,optional-arguments,optional-values,Emacs,Elisp,Optional Parameters,Optional Arguments,Optional Values,我不明白如何在emacs lisp中计算&optional参数 我的代码是: (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 le
(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)))**
在第一部分中,如果我评估测试值54或测试值55,一切都是完美的
但是,当我评估测试值5或测试值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设置为56,如下所示:
(or b (setq b 56))
未提供的可选参数绑定为nil。在函数体中,可以在执行算术之前显式测试nil。在流中,可以将b设置为56,如下所示:
(or b (setq b 56))
多亏了德鲁和斯蒂芬·吉尔德 我接受了你的建议和ligth开发,现在我接受了代码 我反转流程并嵌套第二个代码,如果这是最后一个代码 多谢各位 代码是针对EMACS LISP的 来自墨西哥的问候
(defun test-values (a &optional b)
"Function with an optional argument that tests wheter its argument, a
number, is greater than or equal to, or else, less than the value of
fill-column, and tells you which, in a message. However, if you do not
pass an argument to the function, use 56 as a default value."
(interactive "p")
(if (equal b nil)
(setq value 56)
(if (or (> a b)(equal a b))
(setq value a)
(setq value fill-column)
(message "The value of test is %d" fill-column))))
(test-values 6 3)
(test-values 3 3)
(test-values 3 6)
(test-values 6 nil)
(test-values 6)
现在我可以用nil计算这个函数
非常感谢 感谢德鲁和斯蒂芬·吉尔德 我接受了你的建议和ligth开发,现在我接受了代码 我反转流程并嵌套第二个代码,如果这是最后一个代码 多谢各位 代码是针对EMACS LISP的 来自墨西哥的问候
(defun test-values (a &optional b)
"Function with an optional argument that tests wheter its argument, a
number, is greater than or equal to, or else, less than the value of
fill-column, and tells you which, in a message. However, if you do not
pass an argument to the function, use 56 as a default value."
(interactive "p")
(if (equal b nil)
(setq value 56)
(if (or (> a b)(equal a b))
(setq value a)
(setq value fill-column)
(message "The value of test is %d" fill-column))))
(test-values 6 3)
(test-values 3 3)
(test-values 3 6)
(test-values 6 nil)
(test-values 6)
现在我可以用nil计算这个函数
非常感谢 函数>需要两个数字参数。它收到的一个论点是零。您为参数b传递了一个nil值。>5零不算。非常感谢。我将理解可选参数的概念,谢谢。payina是什么意思?函数>需要两个数字参数。它收到的一个论点是零。您为参数b传递了一个nil值。>5零不算。非常感谢。我会理解可选论点的概念谢谢。payina是什么意思?ligth develope是什么意思?ligth develope是什么意思?