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].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With