Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How does this add predicate actually work?

Status
Not open for further replies.

LovelyHandle

Programmer
Mar 11, 2010
1
0
0
US
Hi, I'm trying to teach myself prolog, and have been using learnprolognow.org guide as it seems to be the best available free guide (and my other programming addictions are already expensive enough). Now, it was going fine, until I reached section 3.1.4. and got to this knowledge base:

Code:
add(0,Y,Y).
add(succ(X),Y,succ(Z)) :-
        add(X,Y,Z).

By tracing it I can understand -what- its doing, using the recursive rule to progressively strip X down to 0, equating Z to Y by the first fact, then going back through all the temporary variables created for Z adding the layers of succ(). And I can somewhat understand how this method could be figured out from the given knowledge, but for the life of me I can't understand how prolog figured it out. Can someone give me some clues as to what prolog's "thought process" was?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top