我有一个谓词,目的是打印出哪个国家面积最大(边界最大的国家=最大面积)。这就是我的谓词的样子:
/* If I write get_country(X, 'Europe'). then all the countries in Europe
that isn't bordering a sea gets printed out.
However as you can see I am creating a list
with all of the countries and then I want to
take the largest country from all of these
and print that one out. But instead
all of the countries gets printed out
with their length, ex: X = hungary ; 359 (length) ... */
get_country(Country, Region):-
encompasses(Country,Region,_),
not(geo_sea(_,Country,_)),
setof(Length, country_circumference(Country,Length), Cs),
largest(Cs, X),
write(X).
该谓词中使用的谓词如下:
country_circumference(Country, X):-
setof(Length, get_border_length(Country, Length), Cs),
sum(Cs, X).
largest([X],X).
largest([X|Xs],R) :-
largest(Xs,Y),
R is max(X,Y).
谁能告诉我我在这里做错了什么?我如何简单地将我的所有国家/地区都放入列表中,然后遍历列表以找到具有最大边界的国家,而不是在我将它们放入列表时将它们一个接一个地打印出来?提前致谢。