The objective of this small article is to analyze a very small program programmed in the Prolog programming language in order to understand a bit how this program language works. Prof. William F. Clocksin defines it as “Prolog is a computer programing language that is used for solving problems that involve objects and the relationship between objects. When we say “”John owns the book”, we are declaring that a relationship, ownership, exists between one object ‘John‘ and another individual object ‘the book‘” (Clocksin, 2003).
The object of analysis on this article is the given Prolog program:
parent(dad_tough_guy, babe_ruth). parent(dad_tough_guy, little_kid). parent(john_oldman, dad_tough_guy). parent(mary_oldwoman, dad_tough_guy). grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
The program above declares the following relation:
Dad Tough Guy is parent of Babe ruth;
Dad Tough Guy is parent of Little kid;
John Old man is parent of Dad tough guy;
Mary Old woman is parent of Dad Tough Guy;
The first four lines declares facts. Facts are defined by the Prof. William F. Clocksin as “Suppose we want to tell Prolog the fact that ‘John likes Mary’. This fact consists of two objects, called ‘Mary’ and ‘John’, and a relationship, called ‘likes’. In Prolog, we need to write facts in a standard form, like this:
” (Clocksin, 2003).
The first four lines declares the relation between this family. The last line is a prolog rule that defines that person is grandparent if and only if person x is parent of z AND person z is parent of person y.
Example of queries on the given code:
Figure 1 Example of usage of the Prolog interpreter
Considering the following query:
When executed in the Prolog interpreter, gives the following result:
Figure 2 Output of a Query execution in the Prolog interpreter
Basically, the Prolog interpreter response is the possible fits for the incognito.
Clocksin, Willian F., 2003. Programming in Prolog. 5th ed. Berlin: Springer.
RESOURCES WHICH HELPED ON THE RESULTS
HOW to run a Prolog program – YouTube. 2016. HOW to run a Prolog program – YouTube. [ONLINE] Available at: https://www.youtube.com/watch?v=6Dh7eux76a8. [Accessed 02 February 2016].
Programming In Prolog Part 1 – Facts, Rules and Queries – YouTube. 2016. Programming In Prolog Part 1 – Facts, Rules and Queries – YouTube. [ONLINE] Available at: https://www.youtube.com/watch?v=gJOZZvYijqk. [Accessed 02 February 2016].