If I had a N lists each of length M, how could I write a nice clean function to return a single list of length M, where each element is the sum of the corresponding elements in the N lists?
(starting to learn lisp - go easy!)
This is a job for the map
and apply
functions. Here is a way to do it, with an EDIT suggested by Nathan Sanders:
(define (add-lists . more)
(apply map + more))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With