>>Prolog is so simple that one has the sense that sooner or later someone had to discover it.<<
- (Colmerauer, Roussel, 1996, p. 350)

... then why is Prolog so strange?

(comments from the author of HERCs Prolog implementation)

The quote at the top comes directly from the fathers of Prolog: Alain Colmerauer and Philippe Roussel. If it is true, then why Prolog is not so widely spread as, for example, Basic? The fact remains, people hardly ever hear about Prolog. If they do hear about it, then it is frequently perceived as esoteric or abstract or some kind of a special purpose language. In any case, Prolog is not considered as being particularly useful to do anything useful. Then why do we have this quote? Is Prolog simple? or is it hard? Perhaps, more importantly, we should ask if it is good for anything useful? It seems that we have an interesting case here.

After many years of using Prolog and talking to people about it, I came to the following conclusion. Prolog can not be taught. You have to be exposed to it and you will either get it or not. The longer you are exposed the better are your chances of understanding it. Just like with swimming, you will either swim or sink.

I think I may have one explanation for it. It may be the fact that Prolog is based on a completely different foundation that other languages. To confirm it you may look at the genealogical tree of computer language families. Prolog seems to have no predecessors and no successors. It is a branch growing virtually from nowhere and leading to nowhere. (Maybe it is not a computer language after all?)

When you start learning a new language your mind instinctively tries to find familiar things. Unfortunately, you can't find them in Prolog. No loops, no conditional statements, no objects, not even variables. Instead, you have symbols, backtracking, clauses and lists. Your brain tries to stick with variables because they look familiar. To your surprise, you find that variables in Prolog are something totally and utterly alien.

In other words, Prolog seems unfamiliar. You must forget about what you have learned from other languages and stick with Prolog for a while. It may not be easy. You neither know the foundation nor the language. How to start it then? You can probably start with some books or with some articles and examples from the Internet. They mostly fall into two categories.
1. Start from the language itself. You are presented with this ridiculous example of family tree. In most cases it is about Zeus and his family of goods. This particular example leaves the impression that Prolog may be good for kids. Maybe a nice theoretical dissertation, but not real programming.
2. Start from the foundation. Basically you get a lecture in formal logic. This one is particularly nasty. In most cases you have enough of Prolog half-way-through the introduction. It leaves you an aftertaste that Prolog is good for some crazy scientists lost in their abstract formulas.

Personally, I tend to think that the best way to start with Prolog is to make it looking familiar. For example, take a simple procedure in C/C++ and re-write it in Prolog. This way Prolog clauses will look to some extent just like well known procedures. Deal with variables. Try assignment statement. Then realise that variables can't change their values and try to live with it. Next step could be with backtracking and accepting the fact that program can actually go backwards. A good idea would be to compare it with exception handling. And so on....

Let's have a look again at the original quotation at the top of this page. Is Prolog so simple as it implies? Once you understand Prolog you will probably agree. Personally I agree. Yes, Prolog seems to me simple and natural. Definitely more natural than object-oriented programming. Do you think you will miss all your variables, pointers, loops and objects? Initially yes, you will miss them. However, you will be able to see programming from a very different perspective.


Robert Wolf, December 2009