(defun recursive-sum (L)
(if (null L)
0
(+ (first L) (recursive-sum L))))
What’s wrong with my code piece?
I got this error message:
*** - SYSTEM::READ-EVAL-PRINT: variable SUM.LISP has no value
The following restarts are available:
USE-VALUE :R1 Input a value to be used instead of SUM.LISP.
STORE-VALUE :R2 Input a new value for SUM.LISP.
ABORT :R3 Abort debug loop
ABORT :R4 Abort debug loop
ABORT :R5 Abort main loop
Break 3 [5]>
Considering the error-code you provided, it seems like you are using a variable called
SUM.LISPwhich has no actual value/is not defined at a certain point. Search that variable name in your code and make sure it is always properly defined and within scope. For more information, more source code is needed.As the function you quoted will most likely not work properly I implemented a fixed version:
where, as mentioned in the comments, you decrease the given list each call by one element.