title: using aref inside a dotimes loop in CL?
body: <p>I have an array with dimensions '(3 3 2) as follows with name test-array:</p>
  
  <pre><code>#3A(((0 0) (0 0.1) (0 0.3)) 
      ((1 0) (1 0.1) (1 0.3))
      ((2 0) (2 0.1) (2 0.3)))
  </code></pre>
  
  <p>Note that the most inner lists inside the array (rank 2) are point coordinates, So in general the array would be</p>
  
  <pre><code>#3A(((x0 y0) (x0 y1) (x0 y2)) 
      ((x1 y0) (x1 y1) (x1 y2))
      ((x2 y0) (x2 y1) (x2 y2)))
  </code></pre>
  
  <p>Now I want to use the elements inside this array to make a new array. </p>
  
  <p>On every row (array-rank: 0) of this array, I want to subtract the second xy coordinates from the first and the third xy coordinates from the second. So basically the result that I am looking for in parametric form is:</p>
  
  <pre><code>#3A(((x0-x0 y1-y0) (x0-x0 y2-y1)) 
      ((x1-x1 y1-y0) (x1-x1 y2-y1))
      ((x2-x2 y1-y0) (x2-x2 y2-y1))
  </code></pre>
  
  <p>Is there any simple direct function or operation which does this by only manipulating the initial array?</p>
  
  <p>Since I don't know any direct operation for this, I thought of just making a list out of the initial array to be the <code>:initial-contents</code> of the new array. So the initial aim in this approach would be to get the initial-contents list which is:</p>
  
  <pre><code>   (((x0-x0 y1-y0) (x0-x0 y2-y1)) 
      ((x1-x1 y1-y0) (x1-x1 y2-y1))
      ((x2-x2 y1-y0) (x2-x2 y2-y1))
  </code></pre>
  
  <p>To do this I thought of a code which uses <code>dotimes</code> twice (number of outer loops would be the number of rows and number of inner loops would be the number of columns so to say):</p>
  
  <pre><code>(let ((result-1))
    (dotimes (n (array-dimension test-array 0) result-1)
      (setq result-1
        (append result-1
                (let ((result-2))
                  (dotimes (m (1- (array-dimension test-array 1)) result-2)
                    (setq result-2
                      (append result-2 
                              (list (- (aref test-array n (1+ m) 0)
                                       (aref test-array n m 0))
                                    (- (aref test-array n (1+ m) 1)
                                       (aref test-array n m 1)))))))))))
  </code></pre>
  
  <p>But there is one problem with this which is also the title of the question. Apparently this "parametric" way (using n &amp; m) of giving inputs for <code>aref</code> is not appreciated by CL: <code>(aref test-array n m 0)</code></p>
  
  <p>Why is there such a problem? Can you think of any other way to use aref inside the loops or maybe make the :initial-contents list with another approach?</p>
  
  <p>Note that this is a relatively simple form of my actual question because the actual initial array that I have has dimensions of (21 16 2) and all the x y coordinates are different from each other.</p>
  
  <p>Answers would be really appreciated...</p>