变量作为 LISP 中的未定义函数

Variable as undefined function in LISP

作为一个项目,我需要使用递归在 lisp 中制作一个罗马数字转换器。在处理罗马数字到英文部分时,我 运行 遇到了一个问题,编译器告诉我我的一个变量是一个未定义的函数。我是 lisp 的新手,可以使用该程序的任何提示或技巧。我想知道我必须进行哪些更改才能停止出现该错误,如果有人对我的递归有任何提示,我将不胜感激。

我知道我的代码很乱,但我计划在我有可用的代码时学习所有正确的格式化方法。该函数应该采用罗马数字列表,然后将列表的第一个和第二个元素转换为相应的整数并将它们相加。它递归地被调用直到它命中 NIL 时它将 return a 0 并添加所有剩余的整数并将其显示为一个原子。希望这是有道理的。提前谢谢你。

(defun toNatural (numerals)
  "take a list of roman numerals and process them into a natural number"
  (cond ((eql numerals NIL) 0)
    ((< (romans (first (numerals)))
        (romans (second (numerals))))
     (+ (- (romans (first (numerals))))
        (toNatural (cdr (numerals)))))
    (t
     (+ (romans (first (numerals)))
        (toNatural (cdr (numerals)))))))


(defun romans (numer)
  "take a numeral and translate it to its integer value and return it"
  (cond((eql numer '(M)) 1000)
       ((eql numer '(D)) 500)
       ((eql numer '(C)) 100)
       ((eql numer '(L)) 50)
       ((eql numer '(X)) 10)
       ((eql numer '(V)) 5)
       ((eql numer '(I)) 1)
       (t 0)))

这里是错误。我在这个项目中使用了 emacs 和 clisp。

The following functions were used but not defined:
 NUMERALS
0 errors, 0 warnings

在 Common Lisp 中,形式 (blah) 表示 "call the function blah",形式 (blah foobar) 表示 "call the function foo, with the argument foobar"。因此,当您实际上只想使用变量的值时,您告诉编译器在多个地方调用函数 numerals

此外,除非你有使用"modern mode"的lisp环境,否则"toNatural"所表示的符号与"tonatural""TONATURAL"所表示的相同,不要用大小写来区分断字,用“-”(所以(defun to-natural ...)。