Prolog/What is Prolog

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Prolog is a declarative programming language. This means that in Prolog, you do not write out what the computer should do line by line, as in procedural languages such as C and Java . The general idea behind declarative languages is that you describe a situation. Based on this code, the interpreter or compiler will tell you a solution. In the case of prolog, it will tell you whether a prolog sentence is true or not and, if it contains variables, what the values of the variables need to be.

This may sound like a godsend for programmers, but the truth is that prolog is seldom used purely in this way. Though the declarative idea is the backbone of prolog, it is possible to see prolog code as procedural. A prolog programmer will generally do both depending on the part of the code they are reading or writing. When learning prolog, however, experience in procedural programming is in no way useful. (it is often said that it is easier to learn prolog for someone who does not have any experience in procedural programming than for someone who does)Template:Whom

Prolog is considered a difficult language to masterTemplate:Whom {{citation}}: Empty citation (help), especially when the student tries to rush things, mainly because of the different way of thinking the student has to adopt and amount of recursion in prolog programs. When used correctly, however, prolog can be a very powerful language.

Why Learn Prolog?[edit | edit source]

Learning prolog will certainly not always be as fruitful as learning C++, Java or Python. Prolog is most useful in the areas related to artificial intelligence research, such as problem solving, (path) planning or natural language interpretation. Some fields that are not strictly AI, such as parser building, can also benefit greatly from prolog.

However, those that do not work with natural language systems daily can also benefit greatly from Prolog. As Prolog uses certain programming techniques that are considered difficult or advanced (most notably recursion), Prolog can be a great way of gaining insight into these techniques. A practised Prolog programmer will certainly have an in-depth understanding of such concepts as recursion, searching problem trees, and constraint logic programming. Prolog can even serve as a 'sketching' tool to try out basic programming ideas before implementing them in procedural languages.

Because of its close ties with predicate logic, learning Prolog can lead to a more fluent understanding of predicate logic. (The reverse is true as well: anyone experienced in predicate logic will certainly be able to pick up Prolog faster)

All in all, if you're looking to improve your resume as a web designer, Prolog may not be the way to go. Prolog is still mainly an academic language {{citation}}: Empty citation (help). This doesn't mean it's purely for testing ideas or outlining techniques. Very complex programs have been written in Prolog. Most of all, Prolog is a complex, powerful, and elegant language that can inspire great satisfaction in its users; at times inspiring immense irritation as well.

As stated before, learning Prolog is not easy. Prolog doesn't work as naturally as procedural languages and therefore requires a specific way of thinking. When learning Prolog it's important to take things slow, and let the concepts settle before moving on. It's also advisable to use more than one text or textbook in the learning process to get multiple perspectives on a subject. As a final note, once you've mastered something tricky that wasn't explained clearly here, feel free to edit this text on Wikibooks, so that future students can learn it more easily.


Next: Introduction to logic