Spis treści

List sum 2

Description

Summing a list of integers

Source: The Art of Prolog

Download

Program source code: list_sum_2.pl

Listing

/*
   sumlist(Is,Sum) :- Sum is the sum of the list of integers Is.
*/
     sumlist([I|Is],Sum) :- sumlist(Is,IsSum), Sum is I+IsSum.
     sumlist([],0).
 
%  Program 8.6a   Summing a list of integers

Comments