Knowledge base:
child(martha,charlotte).
child(charlotte,caroline).
child(caroline,laura).
child(laura,rose).
descend(X,Y) :- child(X,Y).
descend(X,Y) :- child(X,Z),
descend(Z,Y).
Query: descend(martha, laura).
Prolog first calls child(martha, laura) which fails and then returns to descend(martha, laura).
Now, it needs to call child(martha, Z) to check the conditions but why does it need to give Z to another variable like _2978? I think it would have been fine to just call (or query) child(martha, Z).
Trace:
Call: (8) descend(martha, laura) ? creep
Call: (9) child(martha, laura) ? creep
Fail: (9) child(martha, laura) ? creep
Redo: (8) descend(martha, laura) ? creep
Call: (9) child(martha, _2978) ? creep % HERE, why does Prolog
% need this extra variable
% _2978 instead of
% utilizing the original Z variable?
Exit: (9) child(martha, charlotte) ? creep
A simpler example:
I have the knowledge base: numeral(0)
Then I query numeral(X). During the trace I can see that the first call is to numeral(_3233).