This is a generic example of a code I'am programming:
(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)))) When I call the function (test) in the REPL it gives me "illegal function call", as you can see below:
> (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 > It seems I'm doing something wrong with the first (loop for) parameters, but I can't find out what. Can anyone help with this, please? Thanks!
EDIT 1:
So, I've made the adjustments @Rainer Joswig and @Xero Smith suggested:
(defun test (a b) (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))) But now, I'm getting the following error:
> (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.