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

pl/prolog/pllib/list_sum_2.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0