This is a repost of a question I answered on StackOverflow. It’s garnered enough attention that I’m reposting it here.
Many study Prolog in college, but I have personally not come in contact with it professionally. The traditional examples given are AI and expert system applications, but what have you used it for and what made Prolog a suitable language for the task?
I develop virtual world educational content for a university. The virtual world depends on a lot of web content. For example, we have a system where students can arrange cooperative work groups that is a pretty ‘normal’ looking web application, a quiz maker, some analysis tools, etc.
We have two systems. One we have to use PHP due to bureaucratic insanity. The other we use Prolog. Developing in the Prolog environment is much, much faster for the same programmer on similar tasks.
On the side I’m working on a game that is partially in the virtual world and partially in a web app. The web app is in Prolog.
What do we get from using Prolog?
we get away from the common PHP antipattern of stuffing slow changing data into DB tables. We access data in DB’s by making it look like facts. Massive coding speedup to just be able to backtrack to get all the rows.
Backtracking gives us an ‘automagic’ method of looping over rows when generating HTML from table data.
We forget how much time we, as engineers, spend looking up and/or memorizing API contracts. One predicate often serves as a number of API’s. This massively reduces code size. And massively reducing code size massively reduces work.
I can often truly think declaratively – I find myself making little expert systems everywhere. For example, right now I’m designing a log in/registration system for the game. Because people are interacting partly in the virtual world and partly through the web site, I want them to flexibly be ‘logged on’ as soon as I believe they are who they say they are. I’ve got a little expert system that does it, and I wrote it by defining what ‘logged on’ means. This sort of code, besides often being much, much clearer and much, much shorter, also tends to be bug free. I’m not some superprogrammer, and I frequently write Prolog programs that are bug free when first run (my editor checks for syntax errors).
Metaprogramming – We don’t need no stinkin’ design patterns! A pattern is something you wish could have in the language but you can’t…. leading to the obvious question, why not?
Code isn’t just convertable to data – code IS data. capitol(‘Kansas’, ‘Topeka’).
Schemaless db everywhere. Organize your data structures in an agile manner. More accurately, you don’t have data, you have knowledge. Data just lies there. Knowledge can be reasoned with.
Case based reasoning reduces coupling.
Separation of stateless and stateful programming makes multithreading easier (admittedly, the actual thread support is sorta painful). [10/2012 -Anniepoo - I think that was a reflection of my lack of understanding of the thread model. Since then I've come to like the thread model].
Radical destructuring, coding in the head, reduces conditional logic (always a good place for bugs) and makes cases clear. Edge case code tends to end up in separate clauses.
It’s a post object world, away from Java’s ‘now make 7 files cause you have 7 differnet chunks of data’
Good data types – structure as you go is a type, like Lisp lists or Clojure Seqs.
Parsing is a fundamental operation. Nobody’s running around shoving config into xml because there’s no other parser around. No regexes, we have full BNF everywhere (and BNF’s are, imho, far easier to understand).
This answer by Torbjörn Josefsson
Our company (www.intologic.com) mostly uses Prolog.
It’s really good for rule-based systems; a.k.a “business rules”, depending on who you’re talking to :)
Our end-customers are Ericsson (for ‘building’ sales solutions for their telephone switches etc), and some banks and insurance companies, whom we supply with the tools to evaluate loan applications, make profitability calculations etc.
Our customers like not having to have the logic hidden in hard-coded modules made by a programmer with little or no interest/knowledge about the area in question (like me!).
In fact, we have a graphical tool that allows even non-programmers to draw all the logic rules that are needed. (Drawing done in Visio, and Prolog code is constructed directly from the drawings)
It’s going very well! The site is not very updated or Anglified (we’re swedish), mainly because we get as many customers as we can handle right now. The partner company that supply us with most of our customers are very enthusiastic about the technology, and they are using it for more and more things in their own systems.
We make different interfaces to the rule-engine for different purposes; the desktop and webservice clients are the ones most used, but there is also a web application under development.
The main hassle is the connection to C# and other languages – I wish they had a less archaic way of connecting to the logic engine than sockets, but the version of Prolog we use (Sicstus) is made in C, and has been refined for many years to be brutally efficient at what it does.