fork download
  1. user(michael).
  2. user(ana).
  3. user(bob).
  4. user(george).
  5. user(john).
  6.  
  7. follows(michael, ana).
  8. follows(ana, bob).
  9. follows(bob, michael).
  10.  
  11. not_member(_, []).
  12. not_member(X, [H|T]) :- dif(X, H), not_member(X, T).
  13.  
  14. follows(A, B, Seen) :- not_member(B, Seen), follows(A, B).
  15. follows(A, B, Seen) :- follows(A, X), not_member(X, Seen), follows(X, B, [A|Seen]).
  16.  
  17. follows_tx(A, B) :- follows(A, B, []).
  18.  
  19. :- follows_tx(michael, bob), writeln('m-b').
  20. :- follows_tx(michael, john), writeln('m-j').
  21. :- follows_tx(A, A), writeln(A), fail.
  22. :- follows_tx(A, B), write(A), write(' -> '), writeln(B), fail.
  23.  
Success #stdin #stdout #stderr 0.03s 6204KB
stdin
Standard input is empty
stdout
m-b
michael -> ana
ana -> bob
bob -> michael
michael -> bob
ana -> michael
bob -> ana
stderr
Warning: /home/uj7FxV/prog.pl:20:
	Goal (directive) failed: user: (follows_tx(michael, john), writeln(m-j))
Warning: /home/uj7FxV/prog.pl:21:
	Goal (directive) failed: user: (follows_tx(_G356, _G356), writeln(_G356), fail)
Warning: /home/uj7FxV/prog.pl:22:
	Goal (directive) failed: user: (follows_tx(_G356, _G357), write(_G356), write( -> ), writeln(_G357), fail)