Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog existence_error following Seven Languages in Seven Weeks

Tags:

prolog

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.

like image 359
Hongseok Yoon Avatar asked Apr 06 '11 07:04

Hongseok Yoon


1 Answers

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

like image 82
Anders Lindahl Avatar answered Nov 17 '22 12:11

Anders Lindahl