I have two lists, each list has lists inside of them. I want to get the third value from the first list and the first value from the second list each time, multiply these items and then add them to sum.
(defvar *list-1* ((item1 1 4) (item2 4 5) (item3 5 8)))
(defvar *list-2* ((1) (3) (5)))
So I want (1*4) + (3*5) + (5*8) = 59
I have the below code so far
(defun get-total (lst lst1)
(loop :for element :in lst
:for element1 :in lst1
:sum (third element)))
And just for fun, here is a non-loop version
and another
loop can do some destructuring for you, so you don't even need to call third, but can just loop for (nil nil a) in the first list, which will bind a to the third value. You can do the same thing with the second list, except with a destructuring list list (b). Then you'd have:
Even though Joshuas
loop
with destructuring is quite neat I thought I'd add how to change your code to do the same without: