Differences between GProlog and SWI-Prolog results: Question about excercises in `Learn Prolog Now!`

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Differences between GProlog and SWI-Prolog results: Question about excercises in `Learn Prolog Now!`

Donald Winiecki
I have a question about exercise 2.2 in LPN!.

In particular, it appears to be the case that
GProlog returns different results than does SWI-Prolog on question 5 in exercise 2.2.

I acknowledge this to be a very low-importance issue.

Text of the exercise is at the bottom of this message.

SWI-Prolog 7.2.2 returns:
?- magic(Hermoine).
Hermoine = dobby ;
Hermoine = hermoine ;
Hermoine = 'McGonagall' ;
Hermoine = rita_skeeter .

GProlog 1.4.4 returns
?- magic(Hermoine).
Hermoine = dobby ? ;
uncaught exception: error(existence_error(procedure,wizard/1),magic/1)

I understand SWI-Prolog's results, but don't understand why GProlog stops when it hits the rule "magic(X):- wizard(X)." Any pointers are terrifically appreciated!

Text of the exercise follows:

Exercise 2.2

We are working with the following knowledge base:

house_elf(dobby).
witch(hermoine).
witch('McGonagall').
witch(rita_skeeter).
magic(X):- house_elf(X).
magic(X):- wizard(X).
magic(X):- witch(X).

Which of the following queries are satisfied?...

1. magic(housde_elf).
2. wizard(harry).
3. magic(wizard).
4. magic('McGonagall').
5. magic(Hermoine).


_don

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Differences between GProlog and SWI-Prolog results: Question about excercises in `Learn Prolog Now!`

"Micha� Bieli�ski"
Dnia 8 Sierpnia 2015, 13:59, So, Donald Winiecki napisał:
> I have a question about exercise 2.2 in LPN!.
>
> In particular, it appears to be the case that GProlog returns different
> results than does SWI-Prolog on question 5 in exercise 2.2.

The heart of the problem is the clause:
magic(X) :- wizard(X).

In the program code predicate wizard is referenced but defined nowhere.

> I understand SWI-Prolog's results, but don't understand why GProlog
> stops  when it hits the rule "magic(X):- wizard(X)." Any pointers
> are terrifically appreciated!

I have the opposite problem!  I understand GNU Prolog's approach but fail
to grasp why SWI does not signal missing definitions by default. :-p

Anyway, how the solver behaves when it hits nonexistent procedure is
configurable.  Use set_prolog_flag(unknown, X) where X can be 'error',
'fail' or 'warning' to change it.

--
Michał


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Differences between GProlog and SWI-Prolog results: Question about excercises in `Learn Prolog Now!`

Donald Winiecki
On Tue, Aug 18, 2015 at 5:15 PM, "Michał Bieliński" <[hidden email]> wrote:
Dnia 8 Sierpnia 2015, 13:59, So, Donald Winiecki napisał:
> I have a question about exercise 2.2 in LPN!.
>
> In particular, it appears to be the case that GProlog returns different
> results than does SWI-Prolog on question 5 in exercise 2.2.

The heart of the problem is the clause:
magic(X) :- wizard(X).

In the program code predicate wizard is referenced but defined nowhere.

> I understand SWI-Prolog's results, but don't understand why GProlog
> stops  when it hits the rule "magic(X):- wizard(X)." Any pointers
> are terrifically appreciated!

I have the opposite problem!  I understand GNU Prolog's approach but fail
to grasp why SWI does not signal missing definitions by default. :-p

​Indeed. I was hoping my question would be forgotten, even though I have been building courage to report that the problem was, as they say, `the loose nut on my keyboard`.

Both SWI-Prolog and GProlog were behaving properly and identically (though reporting the missing definition in their own ways).  The problems were all mine.  Very basic Prolog syntax was being munged by myself, and misinterpreted on top of it all. 

I've been spending a lot of time in Common Lisp the last few weeks but endeavour to get back here soon.
 

Anyway, how the solver behaves when it hits nonexistent procedure is
configurable.  Use set_prolog_flag(unknown, X) where X can be 'error',
'fail' or 'warning' to change it.

--
Michał

​Best,

_don​
 

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog