For Programmers: Free Programming Magazines  


Home > Archive > Prolog > April 2004 > Why does Prolog fail?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Why does Prolog fail?
Alex Povzner

2004-04-05, 1:43 pm

Experts,

I am using the following simple code with SWI Prolog:

fact(car,have,wheel).
fact(car,contain,engine).
fact(car,contain,cylinder).
fact(contain,specialize,have).

fact(X,G,Y):-fact(S,specialize,G),fact(X,S,Y).

Then I use the following query:

fact(car,have,X)

SWI prolog (and some other prolog interpreters) fails with Out of Stack
Error. I fail to see any infinite recursion in the code,

Alex


bart demoen

2004-04-05, 2:40 pm

Alex Povzner wrote:
> Experts,
>
> I am using the following simple code with SWI Prolog:
>
> fact(car,have,wheel).
> fact(car,contain,engine).
> fact(car,contain,cylinder).
> fact(contain,specialize,have).
>
> fact(X,G,Y):-fact(S,specialize,G),fact(X,S,Y).
>
> Then I use the following query:
>
> fact(car,have,X)
>
> SWI prolog (and some other prolog interpreters) fails with Out of Stack
> Error.


Your "some other prolog interpreters" suggest that some did not ...
BTW, Prolog is written with a capital first letter.

> I fail to see any infinite recursion in the code,


Remove the facts, and just keep the recursive rule.
Do you now see the infinite recursion ?
Do you expect such infinite recursion to go away when you add back the
facts ?

Cheers

Bart Demoen


Bill Spight

2004-04-10, 8:31 am

Dear Alex,

> fact(car,have,wheel).
> fact(car,contain,engine).
> fact(car,contain,cylinder).
> fact(contain,specialize,have).
>
> fact(X,G,Y):-fact(S,specialize,G),fact(X,S,Y).
>


The first thing that struck me is that

fact(car, have, wheel).

is a different kind of thing from

fact(contain, specialize, have).

In most cases, I would think that they deserve different predicates. And
that appears to be the case here.

As for the infinite recursion, what happens when

fact(A, specialize, B)

matches

fact(X, G, Y)

in the last clause?


Good luck!

Bill
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com