by octo_t · 13y ago · 0 comments
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)
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.
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).
Its fairly trivial to write a checkers AI in prolog if you can define what you want + need:
double([], []).
double(H | T, H2 | T2) :- H2 is H * 2, double(T, T2). 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