:- include(mondial).
citypops(C,P) :- bagof(Pop,N^P^Lo^La^El^city(N,'D',P,Pop,Lo,La,El),B).

sum(X,[H|T]) :- sum(Y,T), H \= null, Y \= null, X is H + Y.
sum(H,[H|T]) :- sum(null,T), H \= null.
sum(X,[null|T]) :- sum(X,T).
sum(null,[]).

% Test:  ?- sum(N,[1,2,3,4,5]).      yields 15

citypopsum(C,X) :- citypops(C,B), sum(X,B).

% citypopsum('A',X).
% X = 2434525
