views:

900

answers:

5

By Logic Programming I mean the a sub-paradigm of declarative programming languages. Don't confuse this question with "What problems can you solve with if-then-else?"

A language like Prolog is very fascinating, and it's worth learning for the sake of learning, but I have to wonder what class of real-world problems is best expressed and solved by such a language. Are there better languages? Does logic programming exist by another name in more trendy programming languages? Is the cynical version of the answer a variant of the Python Paradox?

+1  A: 

One of the things Prolog gives you for free is a backtracking search algorithm -- you could implement it yourself, but if your problem is best solved by having that algorithm available, then it's nice to use it.

The two things I've seen it be good at is mathematical proofs and natural language understanding.

Lou Franco
+1  A: 

Prototyping. Prolog is dynamic, and has been for 50 years. Tthe compiler is liberal, the syntax minimalist, and Doing Stuff is easy, fun and efficient. SWI-Prolog has a built-in tracer (debugger!), and even a graphical tracer. You can change code on the fly, using make/0, you can dynamically load modules, add a few lines of code without leaving the interpreter, or edit the file you're currently running on the fly with edit(1). You think you've found a problem with the foobar/2 predicate?

?- edit(foobar).

And as soon as you leave the editor, that thing is going to be re-compiled. Sure, Eclipse does the same thing for Java, but Java isn't exactly a prototyping language.

Apart from the pure prototyping stuff, Prolog is incredibly well suited for translating a piece of logic into code. So, automatic provers and that type of stuff can easily be written in Prolog.

The first Erlang interpreter was written in Prolog - and for a reason, since Prolog is very well suited for parsing, and encoding the logic you find in parse trees. In fact, Prolog comes with a built-in parser! No, not a library, it's in the syntax, namely DCGs.

Prolog is used a lot in NLP, particularly in syntax and computational semantics.

But, Prolog is underused, and underappreciated. Unfortunately, it seems to bear an academic or `unusable for any real purpose' stigma. But it can be put to very good use in many real-world applications involving facts and the computation of relations between facts. It is not very well suited for number crunching, but CS is not only about number crunching.

Aleksandar Dimitrov
"Prolog is dynamic, and has been for 50 years"There's an irony in that statement!
Draemon
+1  A: 

Prolog is ideal for non-numeric problems. This article gives a few examples of some applications of Prolog and it might help you understand the type of problems that it might solve.

Vincent Ramdhanie
+2  A: 

Prolog is great at solving puzzles and the like. That said, in the domain of puzzle-solving it makes easy/medium puzzle-solving easier and complicated puzzle solving harder. Still, writing solvers for grid puzzles and the like such as Hexiom, Sudoku, or Nurikabe is not especially tough.

Brian
I don't see how it makes solving complicated puzzles harder, FWIW.
wnoise
It is often useful to take a fully imperative approach (complete with state and the like) for at least part of the solution. You can fake it with Prolog, but it's often easier in other languages. Especially when it's time to optimize. A built in search is less helpful once thinks get crazy.
Brian
A: 

One simple answer is "build systems". The language used to build Makefiles (at least, the part to describe dependencies) is essentially a logic programming language, although not really a "pure" logic programming language.

mipadi