Lisp SBCL-“;非法函数调用";循环内函数

Lisp SBCL-“;非法函数调用";循环内函数,lisp,common-lisp,Lisp,Common Lisp,这是我正在编程的代码的一般示例: (defun test (a b) (loop for x in '(a b) collect ((setf a (+ a b)) (loop for y in '(a b) (setf a (+ a b)) (loop for z in '(a b) (setf a (+ a b)))) (list a b)))) 当我在REPL中调用函数(test)时,它给出了

这是我正在编程的代码的一般示例:

(defun test (a b)
  (loop for x in '(a b) collect
    ((setf a (+ a b))
    (loop for y in '(a b) 
          (setf a (+ a b))
          (loop for z in '(a b) 
            (setf a (+ a b))))
    (list a b))))
当我在REPL中调用函数(test)时,它给出了“非法函数调用”,如下所示:

> (test 1 1)

debugger invoked on a SB-INT:COMPILED-PROGRAM-ERROR in thread
#<THREAD "main thread" RUNNING {10005E85B3}>:
  Execution of a form compiled with errors.
Form:
  ((SETF A (+ A B))
 (LOOP FOR Y IN '(A B) (SETF A (+ A B)) (LOOP FOR Z IN '(A B) (SETF A
                                                                      (+ A
                                                                         B))))
 (LIST A B))
Compile-time error:
  illegal function call

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [ABORT] Exit debugger, returning to top level.

(FRED5 #<unused argument> #<unused argument>)
   source: ((SETF A (+ A B))
            (LOOP FOR Y IN '(A B) (SETF A (+ A B)) (LOOP FOR Z IN '(A B) (SETF A
                                                                                 (+
                                                                                  A
                                                                                  B))))
            (LIST A B))
0] 0

>
但现在,我得到了以下错误:

> (test 1 1)

debugger invoked on a SB-INT:COMPILED-PROGRAM-ERROR in thread
#<THREAD "main thread" RUNNING {10005E85B3}>:
  Execution of a form compiled with errors.
Form:
  (LOOP FOR X IN '(A B)
      COLLECT (SETF A (+ X 1)) (LOOP FOR Y IN '(A B)
                                     DO (SETF A (+ Y 1)) (LOOP FOR Z IN '(A B)
                                                               DO (SETF A
                                                                          (+ Z
                                                                             1)))) (LIST
                                                                                    A
                                                                                    B))
Compile-time error:
  during macroexpansion of (LOOP FOR X ...). Use *BREAK-ON-SIGNALS* to intercept.

 (LOOP FOR Y IN '(A B)
       DO (SETF A (+ Y 1)) (LOOP FOR Z IN '(A B)
                                 DO (SETF A
                                            (+ Z
                                               1)))) found where a LOOP keyword or LOOP type keyword expected
current LOOP context: COLLECT (SETF A (+ X 1)) (LOOP FOR Y IN '(A B)
                                                     DO (SETF A
                                                                (+ Y
                                                                   1)) (LOOP FOR Z IN '(A
                                                                                        B)
                                                                             DO (SETF A
                                                                                        (+
                                                                                         Z
                                                                                         1)))).

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.
>(测试1)
在线程中的SB-INT:COMPILED-PROGRAM-ERROR上调用调试器
#:
执行带错误编译的表单。
表格:
(用于X英寸(A和B)的环路
收集(SETF A(+X 1))(Y在(A和B)中的循环)
DO(设定值A(+Y 1))(Z在’(A和B)中的循环
DO(SETF)A
(+Z)
1) )(名单
A.
B) )
编译时错误:
在(X的循环…)的宏扩展期间。使用*断开信号*进行拦截。
(Y在(A和B)中的循环)
DO(设定值A(+Y 1))(Z在’(A和B)中的循环
DO(SETF)A
(+Z)
1) ))找到需要循环关键字或循环类型关键字的位置
当前循环上下文:COLLECT(setfa(+x1))(在’(ab)中为Y循环
DO(SETF)A
(+Y)
1) )(A中Z的循环
(B)
DO(SETF)A
(+
Z
1)))).
键入“帮助”以获取调试器帮助,或键入(SB-EXT:EXIT)以退出SBCL。

这是您的问题:
((setf a(+ab))
将其替换为
(setf a(+ab))
。这是一个错误,因为表达式
((setf a(+ab))
不是函数。

这是您的问题:
((setf a(+ab))
将其替换为
(setf a(+ab))
。这是一个错误,因为表达式
((setf a(+a b))
不是一个函数。

您的修复程序仍然错误。
collect
使用单个表单作为其参数。您现在有了
collect(setf…(loop…)

(defun test (a b)
  (loop for x in '(a b) collect  ; X unused
        ((setf a (+ a b))      ; error: not a function, too many parentheses
         (loop for y in '(a b)    ; Y unused
               (setf a (+ a b))       ; error: no DO 
               (loop for z in '(a b)   ; z unused
                     (setf a (+ a b))))  ; error: no DO
         (list a b))))
另一方面,
do
子句有多种形式

也许您正在寻找或关闭此函数:

(defun test (a b)
  (loop for x in '(a b)
        do (setf a (+ a b))
           (loop for y in '(a b) 
                 do (setf a (+ a b))
                    (loop for z in '(a b) 
                          do (setf a (+ a b))))
        collect (list a b))))
如果要将外部
setf
for y
循环和
(列表a b)
组合成一个
collect
子句,则需要
progn

(defun test (a b)
  (loop for x in '(a b)
        collect (progn (setf a (+ a b))
                       (loop for y in '(a b) 
                             do (setf a (+ a b))
                                (loop for z in '(a b) 
                                      do (setf a (+ a b))))
                       (list a b))))

您的修复程序仍然错误。
collect
使用单个表单作为其参数。您现在有了
collect(setf…(loop…)

另一方面,
do
子句有多种形式

也许您正在寻找或关闭此函数:

(defun test (a b)
  (loop for x in '(a b)
        do (setf a (+ a b))
           (loop for y in '(a b) 
                 do (setf a (+ a b))
                    (loop for z in '(a b) 
                          do (setf a (+ a b))))
        collect (list a b))))
如果要将外部
setf
for y
循环和
(列表a b)
组合成一个
collect
子句,则需要
progn

(defun test (a b)
  (loop for x in '(a b)
        collect (progn (setf a (+ a b))
                       (loop for y in '(a b) 
                             do (setf a (+ a b))
                                (loop for z in '(a b) 
                                      do (setf a (+ a b))))
                       (list a b))))