domains
list=symbol*
predicates
path(symbol,symbol)
solve(symbol,symbol,list)
insert(symbol,list,list)
clauses
path(a,b).
path(b,c).
path(c,d).
path(d,e).
path(a,d).
path(c,e).
solve(X, Z, P):-
path(X,Z),
insert(Z,Temp,P),
P=Temp.
solve(X,Z,P):-
path(X,Y),
insert(Y,Temp,P),
P=Temp,
solve(Y,Z,P).
insert(X,[X|Tail],Tail).
insert(X,[Y|Tail],[Y|Tail1]):-
insert(X,Tail,Tail1).
Want to print the path which i have followed in going from one point to another.But getting errors.For examples, i want:
goal
solve(a,c,P).
Answer:P=[a,b,c]
I don't get what your solve predicate does. Here is my guess about how it should be :
solve will give you the paths one after another using the
;
to browse them (well, I guess at least since I don't know anything about the prolog implementation you're using).