next up previous contents
Next: Insertion Sort Up: Examples for recursion Previous: Calculating the faculty of   Contents


Calculating the sum of elements of a list


(define sum
   (lambda(l)
      (if (nullp l)
         zero
         (add (car l) (sum (cdr l))))))


(define l1 (cons one (cons two (cons three nil))))
;
(ndisp! (sum l1))
                             --> 6



Georg P. Loczewski 2004-03-05


Impressum und Datenschutz