Recursion newLISP无效函数

Recursion newLISP无效函数,recursion,newlisp,Recursion,Newlisp,我有一个家庭作业,我们需要用newLISP编写一些函数。我遇到了一个问题,所以我举了一个例子,看看是否有人能帮我解决这个问题 问题是递归函数结束后,它返回一个ERR:invalid function:error。无论我调用的函数是什么,都会发生这种情况 例如,我创建了一个递归函数,它递减一个数字直到达到0。代码如下: (define (decrement num) (if (> num 0) ( (println num) (decrement

我有一个家庭作业,我们需要用newLISP编写一些函数。我遇到了一个问题,所以我举了一个例子,看看是否有人能帮我解决这个问题

问题是递归函数结束后,它返回一个
ERR:invalid function:
error。无论我调用的
函数是什么,都会发生这种情况

例如,我创建了一个递归函数,它递减一个数字直到达到0。代码如下:

 (define (decrement num)
   (if (> num 0)
     (
       (println num)
       (decrement (- num 1))
     ) 
     
     (
       (println "done")
     )
   ) 
 )
每当我运行此函数时,从数字10开始,输出如下所示:

> (decrement 10)
10
9
8
7
6
5
4
3
2
1
done
ERR: invalid function : ((println "done"))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement 10)
(define (decrement num)
   (if (> num 0)
      (begin
        (println num)
        (decrement (- num 1))
      )
      (println "done")
   ) 
 )
我无法理解为什么返回无效函数错误。我对newLISP知之甚少,所以这可能是一个简单的问题


谢谢

在Lisp中,不能使用任意括号将内容分组。所以你应该这样做:

> (decrement 10)
10
9
8
7
6
5
4
3
2
1
done
ERR: invalid function : ((println "done"))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement (- num 1))
called from user function (decrement 10)
(define (decrement num)
   (if (> num 0)
      (begin
        (println num)
        (decrement (- num 1))
      )
      (println "done")
   ) 
 )

谢谢你,这解决了我的问题,帮助我明白我做错了什么!