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 first prolog code.
likes(wallace, cheese).
likes(grommit, cheese).
likes(wendolene, sheep).
friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
If I type likes(wallace, cheese).
on prolog interpretor, I've got error
uncaught exception: error(existence_error(procedure,likes/2),top_level/0).
Prolog 1.3.1 could not be installed in my Mac, I'm using prolog 1.4.0.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With