t3x.org / sketchy / library / length.html
SketchyLISP
Reference
  Copyright (C) 2006
Nils M Holm

length

Conformance: R5RS

Purpose: Compute the length of a list. The result is a natural number.

Arguments:
X - list

Model:

(define (length x)
  (cond ((null? x) 0)
    (#t (n+ (length (cdr x)) 1))))

Implementation:

(define (length x)
  (letrec
    ((_length (lambda (x r)
      (cond ((null? x) r)
        (#t (_length (cdr x) (n+ r 1)))))))
    (_length x 0)))

Example:

(length '(a b c d e f)) 
=> 6

See also:
digits, append, list-tail.