common-lisp - 普通口齿不清 : Undefined function k

标签 common-lisp

我是 Common Lisp 的新手。我尝试构建自己的运算符函数。 在第一个函数中,我尝试将一个加到给定的数字上。 第二个函数我们递归使用第一个函数,频率为 m。 当我输入 totaladd ( 5 3 ) 时,我希望得到 8。 对于未定义的函数 k,我该怎么办?

(defun add1(n)
    (+ n 1)
    )

(write (add1 5))

(defun totaladd (k m)
    (if (eq m 0)
        0
        (totaladd(add1(k) (- m 1)))
    )
)

(write (totaladd 5 3))

最佳答案

下一行有3处错误:

(totaladd(add1(k) (- m 1)))

让我们看一下:

(totaladd                 ; totaladd is a function with two parameters
                          ;  you pass only one argument -> first ERROR
  (add1                   ; add1 is a function with one parameter
                          ;  you pass two arguments -> second ERROR
    (k)                   ; K is a variable, but you call it as a function,
                          ;   but the function K is undefined -> third ERROR
    (- m 1)))

关于common-lisp - 普通口齿不清 : Undefined function k,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51534922/

相关文章:

lisp - Common Lisp 中反引号和引号之间的语义区别是什么?

lisp:如何在范围内创建临时方法特化

common-lisp - 普通口齿不清 : read list into list

file-io - 在 Common Lisp 中处理并发文件访问

common-lisp - 重新定义内置功能

common-lisp - 如何将字符附加到字符串的末尾

common-lisp - 在 Common Lisp 中,如何测试变量是否特殊?

lisp - 使用 Lisp : define a function that takes a list and a number and returns true if the number occurs in the list

LISP:为什么我不能在空列表上使用 cons?

lisp - 帮助理解 lisp 中的这一行