Question on Arrays Code
Posted: Sat Jun 28, 2014 9:05 am
Hi. I was looking at implementing some matrix functions and have some questions on style and efficiency. My use of arrays is limited, so it took me a few hours to come up with this :
And yes, I know I need to implement bounds checking... My concern is are there better solutions for this? Thanks.
Code: Select all
(defun mult-arrays (&rest arrays)
(let ((temp-array (make-array (array-dimension (car arrays) 0) :initial-element 1))) ;; use temporary array as accumulator
(dolist (aX arrays)
(dotimes (i (array-dimension aX 0))
(setf (aref temp-array i) (* (aref temp-array i) (aref aX i)))))
temp-array))
(mult-arrays #(23 45 17 9 27)) ;==> #(23 45 17 9 27)
(mult-arrays #(12 3 0 8) #(2 3 8 12)) ;==> #(24 9 0 96)