4

Currently working through the Seven Languages in Seven Weeks book, and am stuck on getting the first prolog examples to run. This concerns the same code piece as this question; however I believe my question is quite different.

I have defined likes and friend as in the book; my friends.pl:

likes(wallace, cheese).
likes(grommit, cheese).
likes(wendolene, sheep).

friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).

I am using gnu prolog (v1.4.5, on Ubuntu 18.10), and I can load the friends.pl consultfile, either via | ?- [friends.pl] or | ?- ['friends.pl'] or by calling gprolog with its --consult-file parameter: gprolog --consult-file friends.pl just fine

Asking about the likes facts or the first part of the friend rule works just fine:

| ?- likes(grommit, cheese).

yes
| ?- friend(grommit, grommit).

no

However, when I try a query which concerns the second part of the rule, I get this:

| ?- friend(grommit, wendolene).
uncaught exception: error(existence_error(procedure,likes/0),friend/0)

As I read the error message, it tells me that there is no procedure "likes" which takes 0 parameters, right? But where in my rule is such a 0-parameter procedure referenced? What am I doing wrong here? Can't believe this to be a bug in my prolog ;)?

codeling
  • 11,056
  • 4
  • 42
  • 71

1 Answers1

6

There have been several reports of this issue (existence errors for predicates with arity zero that are not called in the source code when a predicate with the same name exists with arity one or greater) with GNU Prolog on Ubuntu. The solution is to download the GNU Prolog sources and compile manually.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • ok, thanks for that hint, I'll try it. so indeed a bug in the Ubuntu version of gprolog ;)? – codeling Feb 02 '19 at 19:21
  • unfortunately, the error only slightly changes ( `/2` instead of `/0` ) with a self-compiled gprolog, see my updated question above – codeling Feb 02 '19 at 19:32
  • 1
    ... forget it, I misspelled `friend` when testing - it works! – codeling Feb 02 '19 at 19:33
  • I had this issue on mint where only the version 1.4.5 is available through apt. Building from source was very fast and easy and there are instructions contained in the tar.gz available from the gnu prolog site. – 5uperdan Mar 26 '19 at 08:51