Guest User

philosophy.m

a guest
Jun 30th, 2014
215
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. % An example of prolog-style logic in Mercury.
  2.  
  3. % This source file is hereby released into the public domain. (mct)
  4.  
  5. %--------------------------------------------------%
  6. :- module philosophy.
  7. %--------------------------------------------------%
  8. :- interface.
  9. %--------------------------------------------------%
  10. %--PUBLIC------------------------------------------%
  11. :- import_module io.
  12.  
  13. :- pred main(io::di, io::uo) is det.
  14.  
  15. %--------------------------------------------------%
  16. :- implementation.
  17. %--------------------------------------------------%
  18. %--PRIVATE-----------------------------------------%
  19. :- import_module solutions, list.
  20.  
  21. %Fact Declarations
  22. :- pred philosopher(string::out) is multi.
  23.  
  24. %Method Declarations
  25. :- pred writeStringsWithNLs(list(string)::in, io::di, io::uo) is det.
  26. % writes strings from a list separating each item with \n. %
  27.  
  28. %--------------------------------------------------%
  29. %--FACTS-------------------------------------------%
  30. philosopher("Socrates").
  31. philosopher("Aristotle").
  32. philosopher("Plato").
  33.  
  34. %--------------------------------------------------%
  35. %--METHODS-----------------------------------------%
  36. main(!IO) :-
  37. io.write_string("The following people are philosophers:\n", !IO),
  38. solutions(philosopher, List), writeStringsWithNLs(List, !IO).
  39.  
  40. writeStringsWithNLs([], !IO).
  41. writeStringsWithNLs([X|Xs], !IO) :-
  42. io.write_string(X, !IO), io.nl(!IO),
  43. writeStringsWithNLs(Xs, !IO).
  44.  
  45. %--------------------------------------------------%
  46. %--------------------------------------------------%
RAW Paste Data