users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: differences in implementation


From: Abdel Ali Ed Dbali
Subject: Re: differences in implementation
Date: Thu, 30 Aug 2007 15:18:49 +0200
User-agent: Internet Messaging Program (IMP) H3 (4.1.4)

Quoting randomizer <address@hidden>:


I am using a simple kb from a book "Learn prolog now!",
wizard(ron).
hasWand(harry).
quidditchPlayer(harry).
wizard(X) :- hasBroom(X),hasWand(X).
hasBroom(X) :- quidditchPlayer(X).

gnu prolog answers question wizard(harry).  "no", and swi prolog answers
"yes".
anyone has an idea why does it happen?
--

Hi,

GnuProlog is very close to ISO prolog in most of its concepts. In ISO prolog, 
the clauses of a predicate P/N must be contiguous!
In you example, wizard/1 is not. That's why the second clause was ignored.

| ?- consult('user').
compiling user for byte code...
wizard(ron).
hasWand(harry).
quidditchPlayer(harry).
wizard(X) :- hasBroom(X),hasWand(X).
user:4: warning: discontiguous predicate wizard/1 - clause ignored
hasBroom(X) :- quidditchPlayer(X).

user compiled, 6 lines read - 595 bytes written, 13840 ms

yes

... See the WARNING above.

The listing predicate gives the first clause only.

| ?- listing(wizard).
wizard(ron).

yes

So, you have to use the directive "contiguous" before the first clause of your 
predicate :

| ?- consult('user').
compiling user for byte code...
:- discontiguous(wizard/1).
wizard(ron).
hasWand(harry).
quidditchPlayer(harry).
wizard(X) :- hasBroom(X),hasWand(X).
hasBroom(X) :- quidditchPlayer(X).
user compiled, 7 lines read - 801 bytes written, 34422 ms

yes
| ?- listing(wizard).

wizard(ron).
wizard(A) :-
        hasBroom(A),
        hasWand(A).
yes
| ?- wizard(harry).

yes

Good luck.

Ali.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]