Lisp- "[Function name] Is not a Number"

标签 lisp common-lisp clisp

所以我有这个简单的表达式来计算和列出二次方程的两个根:

(defun QUADRATIC (A B C) (list (/  (+  (- B) (sqrt(- (* B B) - (* 4 A C)))) (* 2 A)) (/  (- (- B) (sqrt(- (* B B) - (* 4 A C)))) (* 2 A))))

但是当我在 CLISP 中使用任意三个数字作为参数对其进行评估时,比如说

(quadratic 2 2 2)

我收到以下错误:(quadratic 2 2 2) is not a number

我确信有一个简单的修复方法,但我想不出来!

最佳答案

您的定义中存在句法错误(使用正确格式化代码的编辑器有助于发现此类错误)。

正确的定义是:

 (defun quadratic (A B C) 
    (list (/  (+ (- B) (sqrt(- (* B B) (* 4 A C)))) 
              (* 2 A)) 
          (/  (- (- B) (sqrt(- (* B B) (* 4 A C)))) 
              (* 2 A))))

当你在 sqrt 调用中有一个额外的 - 时:(sqrt(- (* B B) - (* 4 A C)))) (* 2 A))(第二个-)。

出现特定错误消息的原因是 - used not in function position 是一个引用当前表单的特殊变量(参见 specification)。

关于Lisp- "[Function name] Is not a Number",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42466432/

相关文章:

emacs - 当我尝试在 emacs 中安装自动完成时出现错误

emacs - 新手 : Keybindings error in Elisp

lisp - Common Lisp 中的循环列表

lisp - 将 ' 转换为 lisp 中的引号

lisp - map 车到位 : destructively modify a list of lists

lisp lambda 函数

common-lisp - 在 Lisp 中从字符串创建变量名

lisp - (Common lisp) 扁平化和传递列表

macros - 在宏中将两个变量合并为一个函数名

list - 有关如何处理此 lisp 函数的建议。