Main_Page/Snack Code/List Recursion

**Sum list of integers**

Haskell:

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

Scheme:

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

Erlang:

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

Smalltalk ?

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