Given facts like
foo(1,a).
foo(2,a).
foo(3,b).
how to get a unique result [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
.
The construct +Var^Goal
tells setof/3
not to bind Var
in Goal
.
?- setof(X, Y^foo(Y, X), Result).
Result = [a, b].
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.