Re: Just crashed gprolog

Lindsey Spratt <[email protected]>
Newsgroups gmane.comp.gnu.prolog.bugs
Message-ID <[email protected]>
On Sunday, May 4, 2003, at 02:26  AM, Emmanuel Mogenet wrote:

> ancestor(X,Y) :- parent(X,Y).
> ancestor(X,Y) :- ancestor(X,Z), ancestor(Z,Y)
[snip]
> | ?- ancestor(X,leo).
>
> X = manu ? ;
>
> X = jolene ? ;
>
> X = francis ? ;
> Segmentation fault (core dumped)
>
>
> Am I doing something wrong ?
yes, you have an infinite recursion.

> Is the tree of ancestors that huge that I'm
> causing the unification to fail ?
no.

You have encountered gprolog's graceful method of telling you that you 
have an infinite recursion: it recurses until it overwrites some memory 
and then faults.

Your second ancestor/2 clause: "ancestor(X,Y) :- ancestor(X,Z), 
ancestor(Z,Y)." is "left-recursive" (the first goal is a recursive 
call). This is not supported by Prolog. Once ancestor/2 exhausts the 
solutions for 'ancestor(X,leo)', it gets into an infinite recursive 
loop through this second clause with 'ancestor(X,Z)' trying first to 
find a satisfactory parent/2 solution (which is no longer possible), 
then falling info the second ancestor/2 clause (recursively), which 
tries the parent/2 clauses again then recursively falls into the 2nd 
ancestor/2 clause, etcetera.

This can be simply fixed by:
> ancestor(X,Y) :- parent(X,Y).
> ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y)


Lindsey Spratt
http://homepage.mac.com/lspratt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.