Re: differences in implementation
Abdel Ali Ed Dbali <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.general |
|---|---|
| Message-ID | <[email protected]> |
Quoting randomizer <[email protected]>: > > 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.