title: Array manipulation in Racket: error "expected indexes for shape '(6); given '#(6)"
body: <p>Before writing this question, I tried to simplify my code down just to the part which causes an error, and the simplified code works... so I'll start with that:</p>
  
  <p>This code should take each x value and increment the y entry at the index with x's value. It mutates ys. See example below the code.</p>
  
  <pre><code>#lang racket
  (require math/array)
  (define xs (array #[5 1 3 1]))
  (define ys (mutable-array #[0 0 0 0 0 0 0 0 0 0]))
  (define result (array-map (λ (x) (array-set! ys
                                           (vector x)
                                           (add1 (array-ref ys (vector x)))))
                        xs))
  
  &gt;&gt; ys
  (mutable-array #[0 2 0 1 0 2 0 0 0 0])
  </code></pre>
  
  <p>Now, here is the code I was writing when the error in this question title occurred:</p>
  
  <p>This first function takes an unsorted array and finds the maximum value in it.</p>
  
  <pre><code>(define (make-auxiliary-array unsorted)
    (local ((define size-for-aux (array-ref (array-axis-max unsorted 0)
                                            #()))) 
      (array-&gt;mutable-array (make-array (vector size-for-aux) 0))))
  </code></pre>
  
  <p>This second function is analogous to the working code at top. The only difference seems to be that I define and use an array locally. The array called auxiliary is analogous to ys in the snippet of working code at top.</p>
  
  <pre><code>(define (count-instances unsorted)
    (local ((define auxiliary (make-auxiliary-array unsorted)))
      (array-map (λ (u) (array-set! auxiliary
                                    (vector u)
                                    (add1 (array-ref auxiliary (vector u)))))
                 unsorted)))
  
  &gt;&gt; (count-instances (array #[3 6 4 1 3 4 1 4]))
  array-ref: expected indexes for shape '(6); given '#(6)
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li><p>Why does the (count-instances) function have an error, but the result value does not?</p></li>
  <li><p>I worked out that I need to use (vector u) to make an index from a value. Why should I use vector rather than (array u)? </p></li>
  <li><p>This should perhaps be a whole separate question, but why is (array #[42]) different from (array 42)? </p></li>
  </ol>