title: Lisp Function that Returns a Sum
body: <p>I am trying to write a weird function, so bear with me here. This function should take a list <code>L</code> as a parameter and have a <code>sum</code> variable. If <code>L</code> is not a list, it should return <code>nil</code>. Otherwise, it should iterate through each element of the list and do the following:</p>
  
  <ul>
  <li>If the element is a number and less than zero, it should subtract 1 from the sum.</li>
  <li>If the element is a number and greater than zero, it should add 1 to the sum.</li>
  <li>if the element is 0 or not a number, then it should add 0 to the sum.</li>
  </ul>
  
  <p>Here's the code I have, but it returns 0 regardless of arguments passed in:</p>
  
  <pre><code>(defun sigsum (L)
    (let ((sum 0))                   ;;variable sum
    (if (not (listp L))              ;;if L is not a list
        nil                          ;;return nil
        (dotimes (i (length L))      ;;otherwise loop through L
          (if (numberp (elt L i))    ;;if each element is a number
              (if (&lt; (elt L i) 0)    ;;if is less than 0 subtract 1 from sum
                  (- sum 1)
              (if (&gt; (elt L i) 0)    ;;if greater than 0 add 1 to sum
                  (+ sum 1))
              (+ sum 0))             ;;else add 0 to sum
            (+ sum 0)))              ;;not a number so add 0 to sum
    )
    sum)                             ;;return sum
  )
  </code></pre>
  
  <p>As always, any help is greatly appreciated.</p>