I have sort of hit a dead end with ideas for a simple function I am trying to write called sumprod. Basically, it finds the sum of the product of two separate lists. So for example: (sumprod '(1 2 3) '(2 3)) --> 12, since (1*2*3) + (2*3) = 12.
I know how to find the product of one list, but I am not sure how I would go about finding the product of the second let alone adding its total to the product of the first list.
Here is the necessary Common Lisp code to find the product of one list.
Code: Select all
(defun sumprod (D E)
(cond
((null D) 1)
(t (* (car D) (sumprod (cdr D) E)))
)
)
Code: Select all
(defun sumprod (D E)
(cond
((null E) 0)
((null D) (*(car E) (sumprod D (cdr E))))
((* (car D)(sumprod (cdr D) E)))
)
)
Brock