Re:Learn Prolog Now
by Koshkin on Monday December 24, 2018 @03:31PM
(#18754126)
I think it helps to think of Prolog as something similar to SQL. See, for example, https://stackoverflow.com/questions/2117651/comparing-sql-an....
[ Parent
| on HN ]
Re:Learn Prolog Now
by tom_mellior on Monday December 24, 2018 @07:50PM
(#18755154)
It doesn't really help to think that way. The accepted answer to that StackOverflow question sounds very much like the poster didn't really know what Prolog is (and possibly confused it with Datalog).
Here is code to append two lists in Prolog:
append([], Xs, Xs).
append([X|Xs], Ys, [X|Zs]) :-
append(Xs, Ys, Zs).
You can use this as follows ("?-" is the user input prompt, equations are the system's answers): ?- append([a,b], [c,d], Zs).
Zs = [a, b, c, d].
?- append(Xs, Ys, [a,b,c]).
Xs = [],Ys = [a, b, c] ;
Xs = [a],Ys = [b, c];
Xs = [a, b],Ys = [c];
Xs = [a, b, c],Ys = [].
How would you express the notion of lists in SQL? How would you express the notion of appending two lists? And how would you express the notion of searching for all possible pairs of lists that, when appended, yield the list [a,b,c]?