I\'m just following the book Seven Languages in Seven Weeks.
I\'ve installed gprolog in my Mac machine using command port install gprolog-devel
and run firs
The interactive gprolog interpreter runs queries against a loaded list of predicates, that is why you get the existence_error
exception. You will have to load your predicates into it, either by using an IDE that does the loading for you or doing it manually.
Here's one approach:
| ?- [user].
compiling user for byte code...
likes(wallace, cheese).
likes(grommit, cheese).
likes(wendolene, sheep).
friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
* Press Ctrl-D to end input. *
user compiled, 6 lines read - 909 bytes written, 15538 ms
yes
| ?- friend(wallace,grommit).
yes
| ?- friend(wallace,wendolene).
no
The gprolog manual writes about this in the chapter Consulting a Prolog program