Main_Page/Snack Code/List Recursion

Sum list of integers


sum []     = 0
sum (x:xs) = x + sum xs


(define (sum lst)
  (cond (( null? lst) 0)
        (else (let ((x (car lst)) (xs (cdr lst)))
                (+ x (sum xs))))))


sum([])    -> 0;
sum([H|T]) -> H + sum(T).

Smalltalk ?

--Dokondr 13:44, 28 February 2006 (UTC)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.