Find depth of list

Problem

I want to calculate the depth of the list (how much the list is nested).

Solution

(define (depth a)
  (if (pair? a)
      (+ 1 (apply max (map depth a)))
      0))

Credit: Nils M Holm (ref: depth.scm)

Usage

(depth '(a (b (c d (e)))))
;; ==> 4

Back to the Scheme Cookbook