Path in a graph - back to content

		arc(a,b).		arc(b,c).
		arc(a,c).		arc(a,d).
		arc(b,e).		arc(e,f).
		arc(b,f).		arc(f,g).	

		?- path(a,b). /* is there any path from a to b? */
		?- path(c,g). /* is there any path from c to g? */

		path(X,Y):- arc(X,Y).
		path(X,Y):- arc(X,Z),path(Z,Y).

?- pathall(a,g,R). /* all the paths from node a to node g ! careful ! if path does not have cycles */ R = [a,b,b,e,e,f,f,g] R = [a,b,b,f,f,g] false. pathall(X,X,[]). pathall(X,Y,[X,Z|L]):- arc(X,Z),pathall(Z,Y,L).