views:

762

answers:

5

Every language that is being used is being used for its advantages, generally.

What are the advantages of Prolog?

What are the general situations/ category of problems where one can use Prolog more efficiently than any other language?

+3  A: 

Any other language is illogical captain.

Gamecat
+2  A: 

Compared to what exactly? Prolog is really just the pre-eminent implementation of logic programming so if your question is really about a comparison of programming paradigms well that's really very broad indeed and you should look here.

If your question is more specifically about prolog vs the more commonly seen OO languages I would argue that you're really comparing apples to oranges - the "advantage" (such as it is) is just a different way of thinking about the world, and sometimes changing the way you ask a question provides a better tool for solving a problem.

annakata
compared to C/C++ in particular... solving a 8 queens problem is for example, so easier in Prolog (which I just found out). Why is C vs Prolog like apples and oranges? Can't every C program be converted to Prolog and vice versa??
Lazer
It can (in theory - i.e. I can't think of a counter-example offhand) but just because you can doesn't mean you should. Look at it this way: if it *was* the right choice most of the time then there'd be a lot more prolog programmers than there are.
annakata
@annakata yes, I agree. but I don't know why (there are less Prolog programmers)
Lazer
@Annakata: Not really. Beta was a far better choice than VHS. OS/2 was a far better choice than Windows (back in the mid 90's). The best technology often loses out to external factors.
Eric J.
+2  A: 

Basically, if your program can be stated easily as declaritive formal logic statements, Prolog (or another language in that family) will give the fastest development time. If you use a good Prolog compiler, it will also give the best performance and reliability, because the engine will have had a lot of design and development effort.

Trying to implement this kind of thing in another language tends to be a mess. The cleanest and most general solution probably involves implementing your own unification engine. Even naive implementations aren't exactly trivial, the Warren Abstract Machine has a book or two written about it, and doing better will at the very least involve a fair bit of research, reading some headache-inducing papers.

Of course in the real world, key parts of your program may benefit from Prolog, but a lot of other stuff is better handled using another language. That's why a lot of Prolog compilers can interface with, e.g., C.

Steve314
+1  A: 

I'd say prolog works well for problems where a knowledge base forms an important part of the solution. Especially when the knowledge structure is suited to be encoded as logical rules.

For example, writing a natural language interpreter for a particular problem domain would require a lot of knowledge in that domain. Expert systems also fall within this knowledge driven category.

It's also a nice language to explore solutions to logical puzzles ;-)

Willem
yeah, I just solved the eight queens problem with it, and it was so easy... i don't know why we don't use Prolog more often.
Lazer
@eSKay - two big ones, A). wrong tool for the job syndrome, because the majority of business problems turn out to be more about manipulating objects and OO is consequently a very prevalent and successful paradigm B). prolog is incredibly difficult to grok, and an unholy nightmare to debug
annakata
A: 

One of the best times to use Prolog is when you have a problem suited to solving with backtracking. And that is when you have lots of possible solutions to a problem, and perhaps you want to order them to include/exclude depending on some context. This suggests a lot of ambiguity... as in natural language processing.

It sure would be a lot tidier to write all the potential answers as Prolog clauses. With a imperative language all I think you can really do is write a giant (really giant) CASE statement, which is not too fun.

pfctdayelise