Iterative Implementations of length


(define (length3 lst)
  (let ((n 0))
    (while (pair? lst)
      (set! n (1+ n))
      (set! lst (cdr lst)) )
    n))

(define (length4 lst) (do ((n 0 (1+ n))) ((not (pair? lst)) n) (set! lst (cdr lst)) ) )

Contents    Page-10    Prev    Next    Page+10    Index