[英]Select unique elements in Prolog
Given facts like鉴于事实如
foo(1,a).
foo(2,a).
foo(3,b).
how to get a unique result [a,b]
?如何获得唯一的结果[a,b]
?
setof/3
: The built-in Prolog predicate setof(+Template, +Goal, -Set)
binds Set
to the list of all instances of Template
satisfying the goal Goal
. setof/3
:内置的 Prolog 谓词setof(+Template, +Goal, -Set)
将Set
绑定到满足目标Goal
的Template
的所有实例的列表。
The construct +Var^Goal
tells setof/3
not to bind Var
in Goal
.构造+Var^Goal
告诉setof/3
不要在Goal
绑定Var
。
?- setof(X, Y^foo(Y, X), Result).
Result = [a, b].
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.