title: Why does my lisp code give me ...should be a lambda expression?
body: <pre><code>(defun helper-2 (list) 
    (if (null (first (rest list)))
        0)
    (+ (distance ((car list) (first (rest list)))) 
       (helper-2 (rest list))))
  </code></pre>
  
  <p>I'm new to lisp and I'm writing a program to compute the perimeter of any polygon with input following clockwise order. My logic is that I use a helper method to compute the length of two points next to each other and do the sum. After recursion is done, I will do a separate call to calculate the length from the beginning point to its end and sum everything up. I've finished the distance method which takes 2 points and return the length. </p>
  
  <pre><code>(distance '(2 0) '(4 0)) ;this will output 2
  </code></pre>
  
  <p>helper-2 logic:
       assume we have 3 points a (2 0) b (3 3) c (4 0) This method is expected to sum up the distance between ab and bc. However, I keep getting "(car head) should be a lambda expression" error. Can anyone help? Thank you. Or could anyone give me a better way to compute the perimeter of a polygon?  </p>
  
  <pre><code>(defun square (n) (* n n))
  
  (defun distance (a b)
    (let ((h (- (second b) (second a)))
          (w (- (first b) (first a))))
      (sqrt (+ (square h) (square w)))))
  </code></pre>