bug-prolog
[Top][All Lists]
Advanced

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

Re: Just crashed gprolog


From: Lindsey Spratt
Subject: Re: Just crashed gprolog
Date: Mon, 5 May 2003 09:51:57 -0500


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






reply via email to

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