^
),
except that bagof/3
fails when Goal has no solutions.findall(Templ, Goal, Bag) :- findall(Templ, Goal, Bag, [])
library(pengines)
.
Based on Ciao, but the Ciao version is deterministic. Portability can be
achieved by wrapping the goal in
once/1.
For example:
?- findnsols(5, I, between(1, 12, I), L). L = [1, 2, 3, 4, 5] ; L = [6, 7, 8, 9, 10] ; L = [11, 12].
+Var^
Goal
tells bagof/3
not to bind
Var in Goal. bagof/3
fails if Goal has no solutions.
The example below illustrates bagof/3
and the ^
operator. The variable bindings
are printed together on one line to save paper.
2 ?- listing(foo). foo(a, b, c). foo(a, b, d). foo(b, c, e). foo(b, c, f). foo(c, c, g). true. 3 ?- bagof(C, foo(A, B, C), Cs). A = a, B = b, C = G308, Cs = [c, d] ; A = b, B = c, C = G308, Cs = [e, f] ; A = c, B = c, C = G308, Cs = [g]. 4 ?- bagof(C, A^foo(A, B, C), Cs). A = G324, B = b, C = G326, Cs = [c, d] ; A = G324, B = c, C = G326, Cs = [e, f, g]. 5 ?-