SD83
SD83

Reputation: 29

Prolog: store solutions in a list

This is a very simple question ;)


fact(a).

fact(b).

test(X):-fact(X).


the solutions are X=a; X=b. OK

I'm trying to create: test(X,L):-fact(X), ??? that returns L=[a,b]

can someone help me? Thanks.

Upvotes: 0

Views: 299

Answers (1)

gusbro
gusbro

Reputation: 22585

Use findall/3 to aggregate solutions:

test(L):-
  findall(X, fact(X), L).

Upvotes: 2

Related Questions