Contents    Page-10    Prev    Next    Page+10    Index   

Recursive Length Function Execution


>(defun length (lst)
  (if (null lst)       ; test for base case
      0                ; answer for base case
      (+ 1
         (length (rest lst))) ) )  ; recursive call

>(length '(a b c))

  1> (LENGTH (A B C))
    2> (LENGTH (B C))
      3> (LENGTH (C))
        4> (LENGTH NIL)
        <4 (LENGTH 0)
      <3 (LENGTH 1)
    <2 (LENGTH 2)
  <1 (LENGTH 3)
3