
% William Clocksin, Clause and Effect, Worksheet 6
% Sum of elements of a list of numbers

sum([], 0).
sum([H|T],N) :- sum(T,N1), N is N1 + H.

% with an accumulator
sumA(L,N) :- accumulate(L,0,N).

accumulate([],A,A).
accumulate([H|T],A,N) :- A1 is A + H, accumulate(T,A1,N).
