I want to calculate the depth of the list (how much the list is nested).
(define (depth a) (if (pair? a) (+ 1 (apply max (map depth a))) 0))
Credit: Nils M Holm (ref: depth.scm)
(depth '(a (b (c d (e))))) ;; ==> 4
Back to the Scheme Cookbook