title: Depth of list in scheme
body: <p>I'm trying to write a program in scheme that will find the maximum depth of a list. My code so far is:</p>
  
  <hr>
  
  <pre><code>(define (depth l)
    (define (helper l count)
      ( cond
          ((null? l) count)
          ((not(list? (car l))) (helper (cdr l) count))
          (else (helper (car l) (+ count 1)) )
      )
    )
    (helper l 1)
  ) 
  </code></pre>
  
  <p>It works for lists of this type <code>(depth '(1 2 3 (2))) -&gt; 2</code>, but obviously not for list of the type <code>(depth '( (2) ((3))) -&gt; 3</code>. The problem is that when I first encounter a list, I automatically jump to it increment the count and call it recursively again, ignoring the other elements of the list. I want to fix this problem and I thought of adding another variable <code>temp</code> which to hold the current count for each element in the list and check if it is bigger than <code>count</code> and if it is true I <code>set!</code> <code>count</code> to <code>temp</code>, but again I have a problem with the recursion. My other idea was to use another list in which to <code>append</code> <code>count</code> on every step and find the maximum value in that list, but I couldn't realize that too. Any ideas how to do this problem?</p>