To answer the question, Prolog to find out the value of X, if it exists. As long as we do not know the value of a variable it is said to be unbound or uninstantiated . When a value is found, the variable is said to instantiated or bound to the value. When there is more than one possible answer, Prolog will try to find all of them. This can be answered by finding out if Jeff lectures in a subject which fred studies.
Subject is a variable.
The question consists of two goals . To answer this question, Prolog first finds a course, Subject, for which Jeff is the lecturer and then finds out if Fred studies the Subject which was just found. Prolog solves this problem by proceeding left to right and then backtracking . A good way of picturing what happens when Prolog tries to find a solution and backtracks, is to draw tree diagrams like the one on the next page. After the first solution is found, Prolog retraces its steps up the tree and looks for alternative solutions.