Aim: Write to lisp code to find sum of n numbers. (Using iteration) (Using function)
Software Used: Gnu Common LISP
coding:
>(defun sum-list (numbers)
(if null numbers ) 0
(+ (first numbers) (sum-list (rest numbers)))))
SUM-LIST
> (sum-list '(5 4 6 2))
17
>(defun sum-n-numbers( & rest nums)
(loop for num in nums summing num))
SUM-N-NUMBERS
>(sum-n-numbers 5 4 6 2)
17
OUTPUT :
0 Comments
if you have any problem, please let me know