3 ms·
Prolog is declarative programming take to the maximum (excluding things like Answer Set Programming/clingo etc). In Prolog you ask questions. For example: su
by octo_t 14y ago
Prolog is declarative programming take to the maximum (excluding things like Answer Set Programming/clingo etc).
In Prolog you ask questions.
For example:
subset([1,2],[2]).
then it goes away and says "yes". Or you want to know if any subsets exist:
subset([1,2],B).
B = []
B = [1]
B = [2]
This makes it really really nice for some surprising tasks (Windows NT used to ship with a prolog interpreter for setting up the network)
- philip_roberts 14y agoOoh, I forgot all about prolog! I worked through the 7 languages in 7 weeks book, and solving a sudoku with prolog blew my mind. I think the first "real" programming I did was a sudoku solver in Excel and VBScript (yeuch).
- octo_t 14y agoProlog is really awesome (and impressive) for solvers where there is an "optimum" solution for what you want. Its fairly trivial to write a checkers AI in prolog if you can define what you want + need:
- pacaro 14y agoOr to take his doubling example... double([], []). double(H | T, H2 | T2) :- H2 is H * 2, double(T, T2).
- masklinn 14y agoThat's a lower-level version of map in a language with destructuring: Haskell would let you say double numbers = map (\x -> x * 2) numbers or double [] = [] double (x:xs) = x * 2 : double xs or double = map (*2) I don't think #2 is more declarative than #1, let alone #3. Then again, I don't think any of these versions is very declarative. Declarative would be numpy: doubled = numbers * 2
- xixixao 14y agoI would disagree - in a sense, Prolog is less declarative than Haskell. For example, the order of "procedure calls" matters in Prolog, a sign of imperative programming. There is no such thing in Haskell (unless imperative behavior is being simulated with Monads).
- no-op 14y agoIf you're familiar with or interested in Prolog, I would definitely recommend checking out Mercury. The language home page was just migrated and they're having broken link issues, but here's a link: http://www.mercurylang.org/ http://www.mercurylang.org/ Also, you can check out the wikipedia page for a quick summary: http://en.wikipedia.org/wiki/Mercury_programming_language http://en.wikipedia.org/wiki/Mercury_programming_language The language has a lot of functionality that Prolog doesn't have and (thanks to a strong typing system) performs much better. It just needs a bigger community to support it.