fork download
  1. % 通路の定義
  2. link(a,b).
  3. link(a,c).
  4. link(b,d).
  5. link(c,e).
  6. link(d,f).
  7. link(f,g).
  8. link(f,h).
  9. link(h,g).
  10.  
  11. path(X,Y) :- link(X,Y)|link(Y,X).
  12.  
  13. pathFind(Pos,Pos,_,[Pos]) :- !.
  14. pathFind(Pos,Goal,Path,[Pos|Tail]) :-
  15. not(member(Pos,Path)),
  16. path(Pos,Z),
  17. pathFind(Z,Goal,[Pos|Path],Tail).
  18.  
  19. pathFindAll(Start,Goal) :- pathFind(Start,Goal,[],Path),print(Path),nl,fail.
  20.  
  21. noLoop(X,[]).
  22. noLoop(X,[X|Z]) :- !,fail.
  23. noLoop(X,[Y|Z]) :- noLoop(X,Z).
  24.  
  25. % 探索の指示
  26. :- pathFindAll(a,g).
Success #stdin #stdout #stderr 0.02s 7928KB
stdin
Standard input is empty
stdout
[a,b,d,f,g]
[a,b,d,f,h,g]
stderr
Warning: /home/VEjfE2/prog:21:
	Singleton variables: [X]
Warning: /home/VEjfE2/prog:22:
	Singleton variables: [Z]
Warning: /home/VEjfE2/prog:23:
	Singleton variables: [Y]
Warning: /home/VEjfE2/prog:26:
	Goal (directive) failed: user:pathFindAll(a,g)
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit