Understanding logic programming
This paradigm is based on formal logic. A program written in a language that implements this paradigm is constructed of a set of sentences in a logical form that will express facts and rules about a specific problem domain.
This might sound complicated and strange, but as we will see, the basic concepts of this paradigm are rather simple. Consider the following diagram:
In the preceding diagram, we can see a family tree. Looking at it, we can see the following:
- Anna and Bob have a child, Lisa.
- Lisa and Fred have a child, Karen.
- Fred and Sue have a child, John.
- Karen's grandparents are Anna and Bob.
In a programming language that uses logic programming, we can define this family tree using something called predicates. This will look something like this:
mother(anna,lisa). mother(lisa,karen). mother(sue,john). father(bob,lisa). father(fred,karen). father...