3 ms·
Prolog is useful everywhere proofs are useful. Now, a proof isn't what you may think of as a proof in the general sense. One example of a proof that Prolog is
by adimitrov 8y ago
Prolog is useful everywhere proofs are useful. Now, a proof isn't what you may think of as a proof in the general sense.
One example of a proof that Prolog is good at is solving games, such as solving a particular instance of tic tac toe, or 4-in-a-row. Beyond these toy examples, you can see a good fit in any application which needs to follow a procession of rules. These rules may be in a feeding/bleeding relationship — this is essentially constraint logic programming. The problem goes: given these constraints, does this statement fulfil the constraints? How can I make the statement fit the constraints? Which is the set of statements that fit these constraints?
I know of an industry application in German luxury cars, where the customer can order a car with a lot (a lot a lot) of different features, but some are mutually exclusive. If you have this particular leather seat, you can't have that particular heating unit or whatever. Now tell me if the customer selected a valid configuration, and if not, tell me what the valid configurations "next to" the desired one are.
Another application are DCGs (Definite Clause Grammar), which have the expressive power of regular expressions (EDIT: see below for a correction, it appears they're at least context-sensitive.) If you've done Monadic parsing, DCGs feel kinda similar. They're super-close to Phrase Structure Grammar rules, and used to be part of my linguistics curriculum (I hear it's all ML nowadays. Pity.)
Yes, Prolog fits niche domains. But if you find a domain, such as regular languages or a problem that can be solved by CLP, the elegance of logic programming can hardly be beat. It's really a joy to work with in the right domain. It's absolutely awful as a general purpose programming language, though — mostly because the debugging is so complex, it almost feels nondeterministic (it isn't, but there were many moments at 2 in the morning where I could've sworn it is.)
In principle, Prolog is great for searching for solutions of a formally posed problem. Think of it as a logic search engine. If your problem can be stated in logic, and the logic problem can be evaluated in a finite time, Prolog's your friend.
If not, you'll blow the stack.
- tom_mellior 8y ago> DCGs (Definite Clause Grammar), which have the expressive power of regular expressions. DCGs have a lot more expressive power than regular expressions. They are at least context-sensitive (i.e., stronger than context-free grammars as well). But off the top of my head I don't see why they wouldn't be able to capture recursively enumerable languages (i.e., the languages of completely unrestricted grammars) as well. > Think of it as a logic search engine. Think of it as a logic search engine embedded in a general-purpose programming language, because that's what it is.
- adimitrov 8y agoYou're right, of course. I misremembered. The trouble is that your program can become non-terminating in all but the regular case IIRC. Man it's been 10 years since I've done Prolog, so take what I say with a grain of salt.
- danieldk 8y agoEven in the regular case it can be non-terminating by using left-recursive rules. E.g. consider parsing a*: as --> as, [a]. as --> []. Prolog will recurse infinitely on the first rule.
- jmmcd 8y ago> Think of it as a logic search engine embedded in a general-purpose programming language, because that's what it is. I think this is the whole problem. The Prolog language is not great as a general-purpose language, and the "logic search engine" doesn't need be so closely identified with a particular language. Prolog should be a library, not a language, and not the almost sole representative of a programming paradigm.
- fanf2 8y agoIsn’t that kind of what miniKanren is about, embedding logic programming in conventional languages?