Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % An example of prolog-style logic in Mercury.
- % This source file is hereby released into the public domain. (mct)
- %--------------------------------------------------%
- :- module philosophy.
- %--------------------------------------------------%
- :- interface.
- %--------------------------------------------------%
- %--PUBLIC------------------------------------------%
- :- import_module io.
- :- pred main(io::di, io::uo) is det.
- %--------------------------------------------------%
- :- implementation.
- %--------------------------------------------------%
- %--PRIVATE-----------------------------------------%
- :- import_module solutions, list.
- %Fact Declarations
- :- pred philosopher(string::out) is multi.
- %Method Declarations
- :- pred writeStringsWithNLs(list(string)::in, io::di, io::uo) is det.
- % writes strings from a list separating each item with \n. %
- %--------------------------------------------------%
- %--FACTS-------------------------------------------%
- philosopher("Socrates").
- philosopher("Aristotle").
- philosopher("Plato").
- %--------------------------------------------------%
- %--METHODS-----------------------------------------%
- main(!IO) :-
- io.write_string("The following people are philosophers:\n", !IO),
- solutions(philosopher, List), writeStringsWithNLs(List, !IO).
- writeStringsWithNLs([], !IO).
- writeStringsWithNLs([X|Xs], !IO) :-
- io.write_string(X, !IO), io.nl(!IO),
- writeStringsWithNLs(Xs, !IO).
- %--------------------------------------------------%
- %--------------------------------------------------%
Advertisement
Add Comment
Please, Sign In to add comment