sum_list_integer(+List, ?Sum)

Determine the sum of all integers in a list of integers (first parameter), the sum is unified with the second parameter. The list may only contain integers else sum_list_integer/2 will fail.

This predicate is located in the file 'list.txt', use ensure_loaded/1 to include this file.

see also: conc/3 del/3 largest_number/2 last/2 lengthlist/2 member/2 prefix/2 reverse/2 smallest_number/2 sublist/2 suffix/2 sum_list/2

Example
sum_list_integer([], S). succeeds and the variable S is unified with the value 0
S=0
sum_list_integer([1, 2.4, 3], S). fails because 2.4 is not an integer number
sum_list_integer([1, 2], F). succeeds and the sum is unified with the variable F
F=3

 

 

info@trinc-prolog.com