如何在Prolog中比较列表中的值?

如何在Prolog中比较列表中的值?,prolog,Prolog,名单: 行李=[ (a,1,2), (b,2,3), (c、3、4)] 我想比较列表a中1*2、列表b中2*3和列表c中3*4的结果。 并对结果和输出进行排序,如何在PROLOG中进行排序 谢谢。您可以使用排序/2: ?- findall([Result, Name], (member((Name, A, B), [(a, 3, 2), (b, 1, 3), (c, 3, 4)]), Result is A*B),Output), sort(Outpu

名单: 行李=[ (a,1,2), (b,2,3), (c、3、4)]

我想比较列表a中1*2、列表b中2*3和列表c中3*4的结果。 并对结果和输出进行排序,如何在PROLOG中进行排序


谢谢。

您可以使用
排序/2

?- findall([Result, Name], 
        (member((Name, A, B), [(a, 3, 2), (b, 1, 3), (c, 3, 4)]),
         Result is A*B),Output), 
   sort(Output, SOutput).

SOutput = [[2, a], [6, b], [12, c]].