I have been trying to find the circumference of a country in Prolog.
I have the finished predicate
borders(Country1, Country2, Length)
and
setof(Item, Condition, Set)
which gives a list of all items into the set which fulfill the condition.
To get the circumference I tried doing this:
circumference(C, Country) :-
setof(X, borders(Country,_,X), Set),
sum_list(Set,C).
sum_list([], 0).
sum_list([H|T], C) :-
sum_list(T, Rest),
C is H + Rest.
... but the output I'm getting is only the length between two countries in the border predicate.
My test:
?– circumference(C,angola).
C = 201 ;
C = 1376 ;
C = 2511 ;
C = 1110.
rules:
borders(angola,namibia,1376).
borders(angola,congo,201).
borders(angola,zambia,1110).
borders(angola,zaire,2511).
Why doesn't C
become the sum of these numbers?