tags:

views:

122

answers:

1

How to expand a query into a list?

f(a,b).
f(a,c).
d(a.d).

expand(f(a,X), Out)  -----> Out=[b,c,d]
+3  A: 

Use bagof/3 or setof/3. E.g.:

?- bagof(X, (X = 1; X = 2), L).

L = [1,2]

yes

In your case that would be

?- bagof(X, f(a,X), Out).

starblue
yep that works, thanks!
Absolute0
How can I pass the output of bagof into length?length(bagof(),O).
Absolute0
bagof(X, ..., L), length(L, N). You need to read some introduction to Prolog.
starblue