(defun sum(n)
(cond
((= n 0) 0)
((= n 1) 1)
(T (+ n sum (- n 1)))))
If I call (sum 4)
it should show 10 but it gives me an error : Variable SUM has no value
If I call |
Common Lisp is a Lisp-2, which means that variables and functions are in distinct namespaces. There is a function Your intention may have been to write
(If you wanted to refer to the function |
||||
comments:
|
© Copyright ask.programmershare.com.
Design by ask.programmershare.com
sum
in your function is a variable. You might want to call the functionsum
? Think about using the Lisp syntax for calling functions...(sum -1)
? ;-)sum (- n 1)
instead of(sum (- n 1))
), and the content of the question isn't likely to help future users with the same problem find it.