私は、どの国が最大の面積を持っているかを出力することを目的とする述語を持っています(最大の国境=最大の面積を持つ国)。これは私の述語がどのように見えるかです:
/* 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).
ここで私が間違っていることを誰かに教えてもらえますか? すべての国をリストに追加してから、リストに入れながら 1 つずつ印刷するのではなく、リストをトラバースして最大の境界線を持つ国を見つけるにはどうすればよいですか? 前もって感謝します。