
Ask HN: is Prolog special or enlightening? - QuadrupleA
In the book Coders at Work, Joe Armstrong got me curious about Prolog: &quot;Prolog is a beautiful language but not widely used... Prolog is so different to all the other programming languages. It&#x27;s just this amazing way of thinking.&quot;<p>Another blog post, &quot;Six programming paradigms that will change how you think about coding&quot;, mentioned Prolog as an example of the mind-expanding &quot;declarative programming&quot; paradigm, which got me curious enough to start experimenting with it.<p>As an experienced programmer in C++, Python, SQL and other languages, I found myself thinking, &quot;I could do all this quite easily with a relational database, or with structured data types in a mainstream language.&quot; Defining relationships between data (e.g. &quot;likes(fred, apple).&quot;), boolean predicates (&quot;is_fruit_eater(X).&quot;), etc., could be represented easily with boolean fields, boolean functions, and so on. And searching through your data for certain conditions is pretty trivial with a for loop or recursive search, with the added bonus that you know what the hell is going on algorithmically without having to read the Prolog interpreter&#x27;s source code.<p>But: I&#x27;m a Prolog ignoramus at this point and have only scratched the surface, so I wanted to see if any Prolog veterans on here could shed some light. Is there a moment of enlightenment that comes with a little more persistence and study? Am I missing something? Can it be summed up in mainstream-language terms?<p>People giving advice online seem to take the attitude of &quot;learn everything you possibly can, it can only help your programming knowledge&quot; but with finite time on earth and a bottomless supply of information out there (look at how deep you can go into the game of chess!) that always strikes me a bit glib and uninsightful. So for someone who&#x27;s walked down the Prolog road - how was it worth it?
======
zmonx
Prolog is well worth learning for several reasons. One is practical and easy
to explain: Syntactically, Prolog is a very simple language with a powerful
implicit search mechanism. As one consequence, it lets you _prototype ideas
quickly_ , especially if search is involved in some way, which is almost
always the case in practice.

The second reason is harder to explain. I can only hint at it for now, and you
will understand the full extent once you apply Prolog in actual practice: With
Prolog, you feel closer to the actual task. First, because you will not manage
to even get started unless you manage to express your ideas clearly. Without
this, there is nothing "to do" in Prolog. In other languages, it feels that
you can always "do" something, such as declaring interfaces, types etc., even
if it does not truly help you for the task at hand.

I have sometimes heard students proclaim: "Prolog is so hard! I could easily
solve the task in Java, but I cannot solve it with Prolog." When you ask them
to describe how they would solve the task in Java, they are unable to do it.

In my view, this shows that the tasks we demand from Prolog beginners are
typically already _inherently_ much harder than what we demand from beginners
in most other languages. There is also a reason for this: These simpler tasks
would often be non-issues or at most extremely trivial in Prolog, so we eschew
them entirely.

Second, you are reasoning _directly_ about terms, without any intermediaries
such as pointers, references or even arrays. It's just terms, terms all the
way down. They come into existence by simply _writing them_ , or by stating
the properties that ought to hold, and asking the system to _find_ them. This
second property is specific to logic programming and _not_ present in
functional languages.

In a very real sense, this is close to the ideal of programming: We describe
what we want, and the machine finds it.

Prolog has many other advantages too, such as admitting very simple yet
powerful meta-interpreters, much shorter ones than are possible for Lisp, for
example. The implicit search mechanism and logical variables enable such
features which are missing from most other programming languages.

Finally, constraint logic programming blends in naturally in Prolog. This is a
very important paradigm that is heavily used in specialized industries, making
excellent Prolog skills also very marketable.

------
kazinator
_Logic programming_ is very useful and absolutely worth learning, like object-
oriented programming and functional programming.

Unfortunately, the Prolog implementation of logic programming, arguably, not
so much.

An alternative is to find some general purpose language which supports Prolog
semantics as a library.

E.g. one example is miniKanren, which has been implemented in a number of
languages, many of them Lisps but not all:

[http://minikanren.org/#implementations](http://minikanren.org/#implementations)

[https://stackoverflow.com/questions/28467011/what-are-the-
ma...](https://stackoverflow.com/questions/28467011/what-are-the-main-
technical-differences-between-prolog-and-minikanren-with-resp)

If you're using something like miniKanren, you've got the logic programming,
plus the rest of the language in which to do other things in other ways.

The idea that you specifically have to use Prolog for logic programming is as
outdated as the idea that to do OOP, you must use Smalltalk.

