title: Racket recursive function for returning the sum of a list of squared numbers
body: <p>I am new to Racket, and I am trying to write a recursive function that takes a number <code>n</code> and returns the sum of the squares of the first <code>n</code> integers. For example, <code>(this-function 3)</code> returns 14 because 14 is 9 + 4 + 1 + 0.</p>
  
  <p>I tried creating two separate functions, one that squares each number and returns a list of the squared numbers, and a second that sums up the list. The function the squares each number is:</p>
  
  <pre><code>(define (squared my-list)
    (cond [(empty? my-list) empty]
          [(zero? my-list) 0] 
          [else (cons (expt  my-list 2)
                      (cons (squared   (sub1 my-list)) empty))]))
  </code></pre>
  
  <p>which if I run <code>(squared 3)</code> returns <code>(cons 9 (cons (cons 4 (cons (cons 1 (cons 0 empty)) empty)) empty))</code>.</p>
  
  <p>When I run the second function (the sum function):</p>
  
  <pre><code>(define (sum numbers)
    (cond
      [(empty? numbers) 0]
      [else (+ (first numbers) (sum (rest numbers)))]))
  </code></pre>
  
  <p>and run <code>(sum (squared 3))</code> I get an error message because <code>(squared 3)</code> returns an extra "cons" in the list.</p>
  
  <p>How can I fix this?</p>