'Find set of solutions and terminate in SWI-Prolog?
Here is my program:
reachable(X) :- start(X).
reachable(X) :- link(Y, X), reachable(Y).
start(london).
link(london, paris).
link(paris, london).
link(london, berlin).
link(paris, berlin).
link(berlin, paris).
Now if I query it, I get solutions:
?- reachable(X).
X = london ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
X = paris ;
...
Why does SWI-Prolog keep finding the same solutions?
How can I fix my program to return the set of solutions then halt?
Here's what I am looking for:
?- reachable(X).
X = paris ;
X = london ;
X = berlin ;
No
$ swipl --version
SWI-Prolog version 7.6.4 for amd64
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
